Skip to content

Commit

Permalink
docs(python): use with_columns in shift examples (#11453)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli authored Oct 1, 2023
1 parent d184c59 commit 6c4ce1a
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions py-polars/polars/expr/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2366,18 +2366,18 @@ def shift(self, periods: int = 1) -> Self:
Examples
--------
>>> df = pl.DataFrame({"foo": [1, 2, 3, 4]})
>>> df.select(pl.col("foo").shift(1))
shape: (4, 1)
┌──────┐
│ foo │
│ --- │
│ i64 │
╞══════╡
│ null │
1
2
3
└──────┘
>>> df.with_columns(foo_shifted=pl.col("foo").shift(1))
shape: (4, 2)
┌─────┬─────────────┐
│ foo ┆ foo_shifted
│ --- ┆ ---
│ i64 ┆ i64
╞═════╪═════════════╡
1 ┆ null
2 ┆ 1
3 ┆ 2
4 ┆ 3
└─────┴─────────────┘
"""
return self._from_pyexpr(self._pyexpr.shift(periods))
Expand All @@ -2401,18 +2401,18 @@ def shift_and_fill(
Examples
--------
>>> df = pl.DataFrame({"foo": [1, 2, 3, 4]})
>>> df.select(pl.col("foo").shift_and_fill("a", periods=1))
shape: (4, 1)
┌─────┐
│ foo │
│ --- │
│ str │
╞═════╡
a
1
2
3
└─────┘
>>> df.with_columns(foo_shifted=pl.col("foo").shift_and_fill("a", periods=1))
shape: (4, 2)
┌─────┬─────────────
│ foo ┆ foo_shifted
│ --- ┆ ---
i64 ┆ str
╞═════╪═════════════
1 ┆ a
2 ┆ 1
3 ┆ 2
4 ┆ 3
└─────┴─────────────
"""
fill_value = parse_as_expression(fill_value, str_as_lit=True)
Expand Down

0 comments on commit 6c4ce1a

Please sign in to comment.