Skip to content

Commit

Permalink
Update .filter() docs (#1793)
Browse files Browse the repository at this point in the history
  • Loading branch information
markfairbanks committed Nov 17, 2021
1 parent 7739be2 commit 83f1d6f
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
33 changes: 33 additions & 0 deletions py-polars/polars/eager/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1256,6 +1256,39 @@ def filter(self, predicate: "pl.Expr") -> "DataFrame":
----------
predicate
Expression that evaluates to a boolean Series.
Examples
--------
>>> df = pl.DataFrame({
>>> "foo": [1, 2, 3],
>>> "bar": [6, 7, 8],
>>> "ham": ['a', 'b', 'c']
>>> })
>>> # Filter on one condition
>>> df.filter(pl.col("foo") < 3)
shape: (2, 3)
┌─────┬─────┬─────┐
│ foo ┆ bar ┆ ham │
│ --- ┆ --- ┆ --- │
│ i64 ┆ i64 ┆ str │
╞═════╪═════╪═════╡
│ 1 ┆ 6 ┆ a │
├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
│ 2 ┆ 7 ┆ b │
└─────┴─────┴─────┘
>>> # Filter on multiple conditions
>>> df.filter((pl.col("foo") < 3) & (pl.col("ham") == "a"))
shape: (1, 3)
┌─────┬─────┬─────┐
│ foo ┆ bar ┆ ham │
│ --- ┆ --- ┆ --- │
│ i64 ┆ i64 ┆ str │
╞═════╪═════╪═════╡
│ 1 ┆ 6 ┆ a │
└─────┴─────┴─────┘
"""
return (
self.lazy()
Expand Down
33 changes: 33 additions & 0 deletions py-polars/polars/lazy/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,39 @@ def filter(self, predicate: "Expr") -> "LazyFrame":
----------
predicate
Expression that evaluates to a boolean Series.
Examples
--------
>>> lf = pl.DataFrame({
>>> "foo": [1, 2, 3],
>>> "bar": [6, 7, 8],
>>> "ham": ['a', 'b', 'c']
>>> }).lazy()
>>> # Filter on one condition
>>> lf.filter(pl.col("foo") < 3).collect()
shape: (2, 3)
┌─────┬─────┬─────┐
│ foo ┆ bar ┆ ham │
│ --- ┆ --- ┆ --- │
│ i64 ┆ i64 ┆ str │
╞═════╪═════╪═════╡
│ 1 ┆ 6 ┆ a │
├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
│ 2 ┆ 7 ┆ b │
└─────┴─────┴─────┘
>>> # Filter on multiple conditions
>>> lf.filter((pl.col("foo") < 3) & (pl.col("ham") == "a")).collect()
shape: (1, 3)
┌─────┬─────┬─────┐
│ foo ┆ bar ┆ ham │
│ --- ┆ --- ┆ --- │
│ i64 ┆ i64 ┆ str │
╞═════╪═════╪═════╡
│ 1 ┆ 6 ┆ a │
└─────┴─────┴─────┘
"""
if isinstance(predicate, str):
predicate = col(predicate)
Expand Down

0 comments on commit 83f1d6f

Please sign in to comment.