From 1df9a6c246b0d482a4893870c29261e9a03e290e Mon Sep 17 00:00:00 2001 From: Ritchie Vink Date: Wed, 22 May 2024 08:53:35 +0200 Subject: [PATCH] docs(python): Add a not about index access on struct.field (#16389) --- py-polars/polars/expr/struct.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/py-polars/polars/expr/struct.py b/py-polars/polars/expr/struct.py index 7b9429971537a..636bacdc188b9 100644 --- a/py-polars/polars/expr/struct.py +++ b/py-polars/polars/expr/struct.py @@ -126,6 +126,22 @@ def field(self, name: str | list[str], *more_names: str) -> Expr: │ 2 ┆ cd │ └─────┴─────┘ + Notes + ----- + The `struct` namespace has implemented `__getitem__` + so you can also access fields by index: + + >>> df.select(pl.col("struct_col").struct[1]) + shape: (2, 1) + ┌─────┐ + │ bbb │ + │ --- │ + │ str │ + ╞═════╡ + │ ab │ + │ cd │ + └─────┘ + """ if more_names: name = [*([name] if isinstance(name, str) else name), *more_names]