Skip to content

Commit

Permalink
docs(python): Use pl.field inside with_fields examples. (#16451)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdlineluser authored May 24, 2024
1 parent a4d30b4 commit 8d4529c
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions py-polars/polars/expr/struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def field(self, name: str | list[str], *more_names: str) -> Expr:
... "ccc": [True, None],
... "ddd": [[1, 2], [3]],
... }
... ).select(pl.struct(["aaa", "bbb", "ccc", "ddd"]).alias("struct_col"))
... ).select(pl.struct("aaa", "bbb", "ccc", "ddd").alias("struct_col"))
>>> df
shape: (2, 1)
┌──────────────────────┐
Expand Down Expand Up @@ -168,7 +168,7 @@ def rename_fields(self, names: Sequence[str]) -> Expr:
... "ccc": [True, None],
... "ddd": [[1, 2], [3]],
... }
... ).select(pl.struct(["aaa", "bbb", "ccc", "ddd"]).alias("struct_col"))
... ).select(pl.struct("aaa", "bbb", "ccc", "ddd").alias("struct_col"))
>>> df
shape: (2, 1)
┌──────────────────────┐
Expand Down Expand Up @@ -266,9 +266,9 @@ def with_fields(
└───────────┴──────────┘
>>> df = df.with_columns(
... pl.col("coords").struct.with_fields(
... pl.col("coords").struct.field("x").sqrt(),
... y_mul=pl.col("coords").struct.field("y") * pl.col("multiply"),
... ),
... pl.field("x").sqrt(),
... y_mul=pl.field("y") * pl.col("multiply"),
... )
... )
>>> df
shape: (3, 2)
Expand Down Expand Up @@ -303,6 +303,9 @@ def with_fields(
Additional fields to add, specified as keyword arguments.
The columns will be renamed to the keyword used.
See Also
--------
field
"""
structify = bool(int(os.environ.get("POLARS_AUTO_STRUCTIFY", 0)))

Expand Down

0 comments on commit 8d4529c

Please sign in to comment.