Fix cum_sum window functions with null filling in cudf-polars - #23206
Conversation
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
|
/ok to test d72e3cb |
📝 WalkthroughSummary by CodeRabbit
WalkthroughChangesCumulative window support
Estimated code review effort: 4 (Complex) | ~45 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
| and isinstance(v.children[0], UnaryFunction) | ||
| ): | ||
| v = v.children[0] | ||
| if isinstance(v, UnaryFunction) and v.name == "cum_sum": |
There was a problem hiding this comment.
question: Does this bug apply to any other of the cumulative functions besides cum_sum?
There was a problem hiding this comment.
Yes but cum_sum is the only one we support for window functions
There was a problem hiding this comment.
Gotcha, I would learn towards checking v.name.startswith("cum_") for a little more future-proofing but not a blocker.
| and isinstance(v.children[0], expr.UnaryFunction) | ||
| and v.children[0].name == "rank" |
There was a problem hiding this comment.
question (not sure if possible): But can v.children[0] be an expression who's child is also a expr.UnaryFunction? i.e do we need to traverse potentially nested children to find a rank expr.UnaryFunction?
There was a problem hiding this comment.
Good question, we're pretty limited on the window functions we allow. But I'll double-check
There was a problem hiding this comment.
Thanks, this is a problem and I switched to falling back on the nested unsupported cases in 9f4a5c6
d72e3cb to
9f4a5c6
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
python/cudf_polars/tests/streaming/test_rolling.py (1)
97-108: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winConsider adding all-null/single-element partition cases.
The new test only covers partitions with partial nulls; per-partition edge cases like an all-null partition or a single-row partition for
cum_sum().fill_null()aren't exercised here.As per path instructions, "Ensure test files provide comprehensive edge case coverage (empty, all-null, single-element, mixed types) and do not depend on external datasets."
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@python/cudf_polars/tests/streaming/test_rolling.py` around lines 97 - 108, The test_over_cum_sum_fill_null_per_partition parametrized case only covers partially null partitions; extend its test data or add focused cases to cover an all-null partition and a single-row partition while retaining both forward and backward strategies. Keep the cases self-contained and validate them through assert_gpu_result_equal.Source: Path instructions
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@python/cudf_polars/tests/streaming/test_rolling.py`:
- Around line 97-108: The test_over_cum_sum_fill_null_per_partition parametrized
case only covers partially null partitions; extend its test data or add focused
cases to cover an all-null partition and a single-row partition while retaining
both forward and backward strategies. Keep the cases self-contained and validate
them through assert_gpu_result_equal.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 8a83cc01-6ab9-4a11-99d8-21da428ceea0
📒 Files selected for processing (6)
python/cudf_polars/cudf_polars/dsl/expressions/rolling.pypython/cudf_polars/cudf_polars/dsl/translate.pypython/cudf_polars/cudf_polars/streaming/select.pypython/cudf_polars/cudf_polars/streaming/utils.pypython/cudf_polars/cudf_polars/testing/inject_gpu_engine.pypython/cudf_polars/tests/streaming/test_rolling.py
💤 Files with no reviewable changes (1)
- python/cudf_polars/cudf_polars/testing/inject_gpu_engine.py
🚧 Files skipped from review as they are similar to previous changes (4)
- python/cudf_polars/cudf_polars/streaming/utils.py
- python/cudf_polars/cudf_polars/streaming/select.py
- python/cudf_polars/cudf_polars/dsl/translate.py
- python/cudf_polars/cudf_polars/dsl/expressions/rolling.py
| windowed = [ | ||
| node | ||
| for node in traversal([value]) | ||
| if isinstance(node, expr.UnaryFunction) and node.name in {"rank", "cum_sum"} |
There was a problem hiding this comment.
Can you remind me why we need to check rank but not in the last child.name check below?
Also a small docstring just describing what we're disallowing would be helpful
There was a problem hiding this comment.
It's because the only unary functions we actually care about / support (other than fill null itself) are rank and cum_sum. This first is used to filter for both. And the second check only allows cum_sum because we only support fill_null(cum_sum(...)) not fill_null(rank(...)).
There was a problem hiding this comment.
Added docs in 215bc79
But you're right this isn't easy to reason about since you have to know which window functions are supported. In a follow-up, I'll do some refactoring to make this easier to understand.
|
/merge |
Description
Makes expressions like this work correctly
Closes #23189
This PR also closes #23205 by falling back to a single partition when executing cum_sum window functions without an
order_byset inoverwith multiple ranks.Needed for #22868 because of the change to Q51.
Checklist