A variant of pl.Expr.shift() that allows filling shifted values using another Polars expression.
WarningWhen abs(offset) exceeds the total number of rows
Since expressions are evaluated lazily at runtime, their validity cannot be verified during construction. If abs(offset) equals or exceeds the total row count, the result may behave like a full-column replacement using fill_expr=.
Parameters
expr:pl.Expr
A single Polars expression to shift.
offset:int=1
The number of rows to shift. It must be a non-zero integer. A positive value shifts the column downward (forward), while a negative value shifts it upward (backward).
fill_expr:pl.Expr
Expression used to fill the shifted positions.
Returns
:pl.Expr
A Polars expression with shifted values and custom fill logic.
In the list namespace, it may be easier to think of each row as an element in a list. Conceptually, you’re working with a pl.Series, where each row corresponds to one item in the list.