polars.Series.cumulative_eval

Series.cumulative_eval(expr: polars.internals.expr.Expr, min_periods: int = 1, parallel: bool = False) polars.internals.series.Series

Run an expression over a sliding window that increases 1 slot every iteration.

Warning

This can be really slow as it can have O(n^2) complexity. Don’t use this for operations that visit all elements.

Warning

This API is experimental and may change without it being considered a breaking change.

Parameters
expr

Expression to evaluate

min_periods

Number of valid values there should be in the window before the expression is evaluated. valid values = length - null_count

parallel

Run in parallel. Don’t do this in a groupby or another operation that already has much parallelization.

Examples

>>> s = pl.Series("values", [1, 2, 3, 4, 5])
>>> s.cumulative_eval(pl.element().first() - pl.element().last() ** 2)
shape: (5,)
Series: 'values' [f64]
[
    0.0
    -3.0
    -8.0
    -15.0
    -24.0
]