Skip to content

Add fixed-size rolling window support to cudf-polars#21964

Draft
tolleybot wants to merge 3 commits intorapidsai:mainfrom
tolleybot:feat/fixed-size-rolling-window
Draft

Add fixed-size rolling window support to cudf-polars#21964
tolleybot wants to merge 3 commits intorapidsai:mainfrom
tolleybot:feat/fixed-size-rolling-window

Conversation

@tolleybot
Copy link
Copy Markdown

Description

Translate Polars RollingFunction expression nodes (rolling_sum, rolling_min, rolling_max, rolling_mean, rolling_var, rolling_std) into GPU-executable operations via libcudf's rolling window API.

The new FixedSizeRollingWindow expression class uses a synthetic sequential integer orderby column with grouped_range_rolling_window to implement row-count-based windows through the existing range-based API. This supports configurable window size, center alignment, min_periods, and ddof for variance and standard deviation.

Depends on pola-rs/polars#27108 which exposes RollingFunction in the Polars Python visitor.

Closes #20307
xref #18633

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

Translate Polars RollingFunction expression nodes (rolling_sum,
rolling_min, rolling_max, rolling_mean, rolling_var, rolling_std) into
GPU-executable operations via libcudf's rolling window API.

The new FixedSizeRollingWindow expression class uses a synthetic
sequential integer orderby column with grouped_range_rolling_window to
implement row-count-based windows through the existing range-based API.
This supports configurable window size, center alignment, min_periods,
and ddof for variance/standard deviation.

Closes rapidsai#20307
@copy-pr-bot
Copy link
Copy Markdown

copy-pr-bot bot commented Mar 31, 2026

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions github-actions bot added Python Affects Python cuDF API. cudf-polars Issues specific to cudf-polars labels Mar 31, 2026
@GPUtester GPUtester moved this to In Progress in cuDF Python Mar 31, 2026
Comment on lines +218 to +220
Handles expressions like ``pl.col("x").rolling_sum(window_size=3)``.
Uses a synthetic sequential orderby column with the range-based
rolling window API to implement row-count-based windows.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

libcudf has a row-count based window API. You can use pylibcudf.rolling.rolling_window with integer arguments for the preceding_window and following_window parameters.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, thanks. Switched to pylibcudf.rolling.rolling_window with integer preceding/following arguments directly. The synthetic orderby column and grouped_range_rolling_window detour are gone.

agg_request = self._make_agg_request()
request = plc.rolling.RollingRequest(col.obj, min_periods, agg_request)

(result,) = plc.rolling.grouped_range_rolling_window(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this can just be rolling_window without needing to make the orderby column.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in the same commit. This now passes the integers through to rolling_window.

Use pylibcudf.rolling.rolling_window instead of constructing a
synthetic orderby column for grouped_range_rolling_window. This
simplifies the implementation and avoids unnecessary overhead.
@tolleybot tolleybot force-pushed the feat/fixed-size-rolling-window branch from 00ce2b2 to ed71430 Compare April 3, 2026 14:38
Extract a _ddof property to deduplicate the three fn_params
extraction sites, add a defensive error in _make_agg_request for
unknown aggregation names, and remove the unused fixture column.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cudf-polars Issues specific to cudf-polars Python Affects Python cuDF API.

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

[FEA] Support rolling expressions with fixed-size windows in cudf-polars

3 participants