Skip to content

Support shift over grouped windows in cudf-polars - #23451

Merged
rapids-bot[bot] merged 12 commits into
NVIDIA:mainfrom
rjzamora:basic-shift-over
Jul 28, 2026
Merged

Support shift over grouped windows in cudf-polars#23451
rapids-bot[bot] merged 12 commits into
NVIDIA:mainfrom
rjzamora:basic-shift-over

Conversation

@rjzamora

Copy link
Copy Markdown
Contributor

Adds cudf-polars support for grouped-window shift, including shift(...).over(...) and shift(..., fill_value=...).over(...).

Partially addresses example/feature (7) in #22032. Like existing cum_sum support, implicit-order shift().over(...) without order_by still falls back for multi-rank execution. I plan to remove that limitation for both cum_sum and shift in a follow-up PR.

@rjzamora rjzamora self-assigned this Jul 28, 2026
@rjzamora
rjzamora requested a review from a team as a code owner July 28, 2026 00:22
@rjzamora rjzamora added the feature request New feature or request label Jul 28, 2026
@rjzamora
rjzamora requested a review from nirandaperera July 28, 2026 00:22
@rjzamora rjzamora added 2 - In Progress Currently a work in progress non-breaking Non-breaking change labels Jul 28, 2026
@github-actions github-actions Bot added Python Affects Python cuDF API. cudf-polars Issues specific to cudf-polars labels Jul 28, 2026
@GPUtester GPUtester moved this to In Progress in cuDF Python Jul 28, 2026
@rjzamora

Copy link
Copy Markdown
Contributor Author

cc @Matt711 (since you originally implemented over() support)

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 4c93edfb-604c-4dcd-8b48-8ef9f35f13f0

📥 Commits

Reviewing files that changed from the base of the PR and between f583139 and 5cca1a4.

📒 Files selected for processing (1)
  • python/cudf_polars/tests/streaming/test_rolling.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • python/cudf_polars/tests/streaming/test_rolling.py

📝 Walkthrough

Summary by CodeRabbit

  • New Features
    • Added support for grouped shift and shift_and_fill window expressions, including positive/negative offsets and ordered or unordered grouping with proper fill behavior.
  • Bug Fixes
    • Improved window expression handling so shift-style ops are correctly recognized as input-order-sensitive when order_by is missing.
    • Added stricter validation: shift offset and shift_and_fill fill must be literal values; shift(...).over(...) without order_by can raise in multi-rank mode based on fallback settings.
  • Tests
    • Expanded GPU and streaming coverage for shift(...).over(...), including missing-position semantics and new multi-rank error scenarios.

Walkthrough

Adds grouped window shift and shift_and_fill support, including evaluation, translation, streaming fallback detection, literal argument validation, and GPU, single-rank, and multi-rank tests.

Changes

Grouped window shift support

Layer / File(s) Summary
Shift operation contracts
python/cudf_polars/cudf_polars/dsl/expressions/rolling.py, python/cudf_polars/cudf_polars/dsl/translate.py, python/cudf_polars/cudf_polars/dsl/utils/aggregations.py
Adds ShiftOp, recognizes shift-family window expressions during decomposition and translation, and validates literal offsets and fill values.
Grouped shift evaluation
python/cudf_polars/cudf_polars/dsl/expressions/rolling.py
Evaluates grouped shifts using ordered group scans, per-expression offsets and fills, and restoration of input row order.
Streaming input-order handling
python/cudf_polars/cudf_polars/streaming/utils.py, python/cudf_polars/cudf_polars/streaming/select.py
Expands multi-rank detection and fallback handling to input-order-sensitive cum_sum, shift, and shift_and_fill windows without order_by.
Shift behavior validation
python/cudf_polars/tests/expressions/test_rolling.py, python/cudf_polars/tests/streaming/test_rolling.py, python/cudf_polars/tests/streaming/test_spmd.py
Adds ordered and unordered grouped shift tests, fill-value cases, single-rank execution checks, multi-rank results, and expected unsupported-operation errors.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related issues

  • rapidsai/cudf#22032 — Directly tracks support for shifted over() expressions implemented by this PR.

Possibly related PRs

  • rapidsai/cudf#23206 — Provides related window-expression decomposition and streaming fallback handling generalized here for shift operations.

Suggested labels: improvement

Suggested reviewers: nirandaperera

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding grouped-window shift support in cudf-polars.
Description check ✅ Passed The description accurately matches the grouped-window shift support and the remaining multi-rank fallback limitation.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@Matt711 Matt711 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good, only comment is can you make sure either we fallback or support a nested expression like pl.col("x").shift(1).fill_null(strategy="forward").over("g")?

Comment thread python/cudf_polars/tests/streaming/test_rolling.py
@rjzamora rjzamora added 5 - Ready to Merge Testing and reviews complete, ready to merge and removed 2 - In Progress Currently a work in progress labels Jul 28, 2026
@rjzamora

Copy link
Copy Markdown
Contributor Author

/merge

@rapids-bot
rapids-bot Bot merged commit f38653b into NVIDIA:main Jul 28, 2026
110 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in cuDF Python Jul 28, 2026
@rjzamora
rjzamora deleted the basic-shift-over branch July 28, 2026 20:37
@rjzamora

Copy link
Copy Markdown
Contributor Author

Update: I just pushed #23466 to enable cum_sum(...).over(...) and shift(...).over(...) without the order_by argument.

rapids-bot Bot pushed a commit that referenced this pull request Jul 29, 2026
Follow up to #23451
Fully addresses item (7) of #22032

Adds the necessary per-group sort operation to preserve input row order before evaluating input-order-sensitive `over(...)` expressions without an explicit `order_by` argument.

This allows streaming execution of grouped `shift` and `cum_sum` windows that rely on the incoming row order.

Authors:
  - Richard (Rick) Zamora (https://github.com/rjzamora)

Approvers:
  - Matthew Roeschke (https://github.com/mroeschke)

URL: #23466
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

5 - Ready to Merge Testing and reviews complete, ready to merge cudf-polars Issues specific to cudf-polars feature request New feature or request non-breaking Non-breaking change Python Affects Python cuDF API.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants