Skip to content

Commit

Permalink
add examples to select docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-beedie committed Jan 29, 2023
1 parent ac61ce6 commit 7fe63f5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
18 changes: 17 additions & 1 deletion py-polars/polars/internals/dataframe/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -5589,6 +5589,22 @@ def select(
│ 10 │
└─────────┘
Note that, when using kwargs syntax, expressions with multiple
outputs are automatically instantiated as Struct columns:
>>> from polars.datatypes import INTEGER_DTYPES
>>> df.select(odd=(pl.col(INTEGER_DTYPES) % 2).suffix("_is_odd"))
shape: (3, 1)
┌───────────┐
│ odd │
│ --- │
│ struct[2] │
╞═══════════╡
│ {1,0} │
│ {0,1} │
│ {1,0} │
└───────────┘
"""
return self._from_pydf(
self.lazy().select(exprs, **named_exprs).collect(no_optimization=True)._df
Expand Down Expand Up @@ -5694,7 +5710,7 @@ def with_columns(
│ 4 ┆ 13.0 ┆ true ┆ 52.0 ┆ false │
└─────┴──────┴───────┴──────┴───────┘
Note that, when using kwarg syntax, expressions with multiple
Note that, when using kwargs syntax, expressions with multiple
outputs are automatically instantiated as Struct columns:
>>> df.drop("c").with_columns(
Expand Down
18 changes: 17 additions & 1 deletion py-polars/polars/internals/lazyframe/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1641,6 +1641,22 @@ def select(
│ 10 │
└─────────┘
Note that, when using kwargs syntax, expressions with multiple
outputs are automatically instantiated as Struct columns:
>>> from polars.datatypes import INTEGER_DTYPES
>>> df.select(odd=(pl.col(INTEGER_DTYPES) % 2).suffix("_is_odd")).collect()
shape: (3, 1)
┌───────────┐
│ odd │
│ --- │
│ struct[2] │
╞═══════════╡
│ {1,0} │
│ {0,1} │
│ {1,0} │
└───────────┘
"""
if exprs is None and not named_exprs:
raise ValueError("Expected at least one of 'exprs' or **named_exprs")
Expand Down Expand Up @@ -2537,7 +2553,7 @@ def with_columns(
│ 4 ┆ 13.0 ┆ true ┆ 52.0 ┆ false │
└─────┴──────┴───────┴──────┴───────┘
Note that, when using kwarg syntax, expressions with multiple
Note that, when using kwargs syntax, expressions with multiple
outputs are automatically instantiated as Struct columns:
>>> ldf.drop("c").with_columns(
Expand Down

0 comments on commit 7fe63f5

Please sign in to comment.