Skip to content

Null Support for rolling operations (e.g. rolling_xyz_by) #25848

@CatchemAL

Description

@CatchemAL

Description

I wanted to ask about a small ergonomics improvement around time-based rolling operations with nulls.

Example

import polars as pl
from datetime import datetime

df = pl.DataFrame(
    {
        "date": pl.datetime_range(
            datetime(2025, 1, 1),
            datetime(2025, 1, 5),
            eager=True,
        ),
        "x": [1.0, None, 3.0, 4.0, 5.0],
    }
)

out = df.with_columns(
    rolling = pl.col("x").rolling_mean_by(
        by="date",
        window_size="2d",
    )
)

out

This currently errors with:

InvalidOperationError:
'Expr.rolling_*_by(...)' not yet supported for series with null values
Time based rolling is a very common operation so just wanted to request this as a quality-of-life request.

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedReady for implementationenhancementNew feature or an improvement of an existing featureenterprise-supportPolars enterprise support requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions