Skip to content

Fix slicing after Join and GroupBy in streaming cudf-polars #19187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jun 25, 2025

Conversation

rjzamora
Copy link
Member

Description

The streaming executor does not properly handle slicing after Join or GroupBy. Rather than slicing the "reduced" join/gropuby result, each partition is sliced individually. This PR includes a general fix, by pulling the slice operation out of Join and GroupBy nodes.

Checklist

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

@rjzamora rjzamora self-assigned this Jun 17, 2025
@rjzamora rjzamora requested a review from a team as a code owner June 17, 2025 18:32
@rjzamora rjzamora added bug Something isn't working 2 - In Progress Currently a work in progress non-breaking Non-breaking change cudf-polars Issues specific to cudf-polars labels Jun 17, 2025
@github-actions github-actions bot added the Python Affects Python cuDF API. label Jun 17, 2025
@GPUtester GPUtester moved this to In Progress in cuDF Python Jun 17, 2025
@TomAugspurger
Copy link
Contributor

TomAugspurger commented Jun 18, 2025

edit: probably not an issue. See #19187 (comment)

@rjzamora there's one similar issue on branch-25.08 that doesn't appear to be fixed here:

import polars as pl

from cudf_polars.testing.asserts import assert_gpu_result_equal


left = pl.LazyFrame(
        {
            "a": [1, 2, 3, 1, None],
            "b": [1, 2, 3, 4, 5],
            "c": [2, 3, 4, 5, 6],
        }
    )
right = pl.LazyFrame(
        {
            "a": [1, 4, 3, 7, None, None, 1],
            "c": [2, 3, 4, 5, 6, 7, 8],
            "d": [6, None, 7, 8, -1, 2, 4],
        }
    )

q = left.join(right, on="a", how="left", nulls_equal=False, coalesce=True).slice(1, 5)
assert_gpu_result_equal(q, engine=pl.GPUEngine(executor="streaming", executor_options={"max_rows_per_partition": 4}))

which fails with

AssertionError: DataFrames are different (value mismatch for column 'a')
[left]:  [1, 2, 3, 1, 1]
[right]: [1, 1, 2, None, 1]

I'm starting to investigate that now. Should we handle that in a separate PR?

@TomAugspurger
Copy link
Contributor

TomAugspurger commented Jun 18, 2025

Maybe this is just a join ordering issue. I don't think that left.join(right).slice(...) makes sense unless you've specified a maintain_order. Otherwise, you're just slicing random rows, as chosen by the join implementation.

We do match for this snippet that specifies maintain_order (ignore this; we only match because we don't implement maintain_order and fall back to CPU)

import polars as pl
from cudf_polars.testing.asserts import assert_gpu_result_equal

left = pl.LazyFrame(
    {
        "a": [1, 2, 3, 1, None],
        "b": [1, 2, 3, 4, 5],
        "c": [2, 3, 4, 5, 6],
    }
)
right = pl.LazyFrame(
    {
        "a": [1, 4, 3, 7, None, None, 1],
        "c": [2, 3, 4, 5, 6, 7, 8],
        "d": [6, None, 7, 8, -1, 2, 4],
    }
)

engine = pl.GPUEngine(
    executor="streaming", executor_options={"max_rows_per_partition": 4}
)
q = left.join(right, on="a", how="left", maintain_order="left").slice(1, 5)
assert_gpu_result_equal(q, engine=engine)

so I'll just plan to update #19146 to adjust these tests somehow, probably by specifying the engine explicitly...

@rjzamora
Copy link
Member Author

Maybe this is just a join ordering issue. I don't think that left.join(right).slice(...) makes sense unless you've specified a maintain_order. Otherwise, you're just slicing random rows, as chosen by the join implementation.

Yes, this is exactly how I understand it.

Copy link
Contributor

@TomAugspurger TomAugspurger left a comment

Choose a reason for hiding this comment

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

Sorry, #19186 caused some failures here. I think just removing the config_options should suffice.

@TomAugspurger
Copy link
Contributor

/merge

@rapids-bot rapids-bot bot merged commit d03d87c into rapidsai:branch-25.08 Jun 25, 2025
91 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in cuDF Python Jun 25, 2025
@rjzamora rjzamora deleted the rick/fix/slice branch June 25, 2025 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2 - In Progress Currently a work in progress bug Something isn't working cudf-polars Issues specific to cudf-polars non-breaking Non-breaking change Python Affects Python cuDF API.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants