Skip to content

Commit

Permalink
docs(python): Add a not about index access on struct.field (pola-rs#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 authored and Wouittone committed Jun 22, 2024
1 parent ef74013 commit 1df9a6c
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions py-polars/polars/expr/struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 1df9a6c

Please sign in to comment.