Question: I am working with both pandas and polars for rolling operations, but I am encountering different results when dealing with duplicate timestamps. I want to replicate the pandas behavior in polars. Here’s an example illustrating the issue with rolling_sum: Pandas Code: import pandas as pd import polars as pl data = { "timestamp": [ "2023-08-04 10:00:00", "2023-08-04 10:05:00", "2023-08-04 10:10:00", "2023-08-04 10:10:00", "2023-08-04 10:20:00", "2023-08-04 10:20:00", ], "value": [1, 2, 3, 4, 5, 6], } pddf = pd.DataFrame(data) pddf["timestamp"] = pd.to_datetime(pddf["timestamp"]) pddf.set_index("timestamp", inplace=True) pddf["rolling_sum"] = pddf["value"].rolling("10min").sum() print(pddf)  Output:  value rolling_sum timestamp 2023-08-04 10:00:00 1 1.0 2023-08-04 10:05:00 2 3.0 2023-08-04 10:10:00 3 5.0 2023-08-04 10:10:00 4 9.0 2023-08-04 10:20:00 5 5.0 2023-08-04 10:20:00 6 11.0  Polars Code: pldf = ( pl.DataFrame(data) .with_columns(pl.col("timestamp").str.strptime(pl.Datetime)) .sort("timestamp") .with_columns( pl.col("value") .rolling_sum_by(by="timestamp", window_size="10m") .alias("rolling_sum") ) ) print(pldf)  Output: ┌─────────────────────┬───────┬─────────────┐ │ timestamp ┆ value ┆ rolling_sum │ │ --- ┆ --- ┆ --- │ │ datetime[μs] ┆ i64 ┆ i64 │ ╞═════════════════════╪═══════╪═════════════╡ │ 2023-08-04 10:00:00 ┆ 1 ┆ 1 │ │ 2023-08-04 10:05:00 ┆ 2 ┆ 3 │ │ 2023-08-04 10:10:00 ┆ 3 ┆ 9 │ │ 2023-08-04 10:10:00 ┆ 4 ┆ 9 │ │ 2023-08-04 10:20:00 ┆ 5 ┆ 11 │ │ 2023-08-04 10:20:00 ┆ 6 ┆ 11 │ └─────────────────────┴───────┴─────────────┘  Question: How can I achieve the same rolling_* result in polars as in pandas when dealing with duplicate timestamps? The pandas output includes separate rolling sum calculations for each row with the same timestamp, but polars aggregates them differently. Is there a way to configure polars to handle duplicate timestamps in a similar manner to pandas? My question is related to this polars issue. Thank you in advance for your help!

Answer: AFAIK there are currently no parameters of pl.DataFrame.rolling or pl.Expr.rolling_sum_by allowing to control the handling of duplicate values in the by column. This would probably make a good feature request. Until then, you could explicitly aggregate all values in the window into a list column. For duplicate values in the by column you'd take increasing subsets of the list column and aggregate afterwards. ( pl.DataFrame(data) .with_columns( pl.col("timestamp").str.strptime(pl.Datetime) ) .sort("timestamp") # aggregate values into list column .rolling(index_column="timestamp", period="10m").agg(pl.all()) # take sum of sliced list column to get desired behaviour .with_columns( pl.col("value") .list.slice( 0, pl.col("value").list.len() - pl.int_range(pl.len()).reverse().over("timestamp") ) .list.sum() .name.suffix("_rolling_sum") ) )  shape: (6, 3) ┌─────────────────────┬───────────┬───────────────────┐ │ timestamp ┆ value ┆ value_rolling_sum │ │ --- ┆ --- ┆ --- │ │ datetime[μs] ┆ list[i64] ┆ i64 │ ╞═════════════════════╪═══════════╪═══════════════════╡ │ 2023-08-04 10:00:00 ┆ [1] ┆ 1 │ │ 2023-08-04 10:05:00 ┆ [1, 2] ┆ 3 │ │ 2023-08-04 10:10:00 ┆ [2, 3, 4] ┆ 5 │ │ 2023-08-04 10:10:00 ┆ [2, 3, 4] ┆ 9 │ │ 2023-08-04 10:20:00 ┆ [5, 6] ┆ 5 │ │ 2023-08-04 10:20:00 ┆ [5, 6] ┆ 11 │ └─────────────────────┴───────────┴───────────────────┘