Skip to content

Fix cuda error when sorting empty pl.concat result#21825

Merged
rapids-bot[bot] merged 2 commits intorapidsai:mainfrom
jberg5:fix-21824
Apr 6, 2026
Merged

Fix cuda error when sorting empty pl.concat result#21825
rapids-bot[bot] merged 2 commits intorapidsai:mainfrom
jberg5:fix-21824

Conversation

@jberg5
Copy link
Copy Markdown
Contributor

@jberg5 jberg5 commented Mar 17, 2026

Description

Should close #21824

See test case for repro, but basically if you had

    df = pl.LazyFrame({"a": [1, 2, 3]})
    # Create two filters, both of which will give empty results
    q = pl.concat([df.filter(pl.col("a") == 0), df.filter(pl.col("a") == 4)]).sort("a")

then q.collect(engine="gpu") you'd get a cuda exception because we'd try to do an out of bounds access on an empty table.

edit: turns out #21690 fixed this issue. This PR now will only contribute a test case.

Checklist

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

@jberg5 jberg5 requested a review from a team as a code owner March 17, 2026 20:07
@copy-pr-bot
Copy link
Copy Markdown

copy-pr-bot bot commented Mar 17, 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 17, 2026
@mroeschke mroeschke added bug Something isn't working non-breaking Non-breaking change labels Mar 17, 2026
@mroeschke
Copy link
Copy Markdown
Contributor

/ok to test 8737854

@GPUtester GPUtester moved this to In Progress in cuDF Python Mar 25, 2026
@jberg5
Copy link
Copy Markdown
Contributor Author

jberg5 commented Mar 25, 2026

Looks like #21867 moved the tests into legacy/ - not sure if this changes things, or if a massive rewrite is in the works? @mroeschke what do you think, is this fix still relevant?

@mroeschke
Copy link
Copy Markdown
Contributor

Sorry for the delay @jberg5

On main, I believe we see the correct behavior now

In [1]: import polars as pl

In [2]: df = pl.LazyFrame({"a": [1, 2, 3]})

In [3]: q = pl.concat([df.filter(pl.col("a") == 0), df.filter(pl.col("a") == 4)]).sort("a").collect(engine="gpu")

In [4]: q
Out[4]: 
shape: (0, 1)
┌─────┐
│ a   │
│ --- │
│ i64 │
╞═════╡
└─────┘

So a unit test would still be appreciated (in python/cudf_polars/tests/expressions/test_sort.py would be fine)

@jberg5
Copy link
Copy Markdown
Contributor Author

jberg5 commented Apr 5, 2026

Thanks @mroeschke , just have the test case now.

@mroeschke
Copy link
Copy Markdown
Contributor

/ok to test e032a1b

@mroeschke
Copy link
Copy Markdown
Contributor

/merge

@rapids-bot rapids-bot bot merged commit 6cc9cf7 into rapidsai:main Apr 6, 2026
93 of 94 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in cuDF Python Apr 6, 2026
@mroeschke
Copy link
Copy Markdown
Contributor

Thanks again @jberg5

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

Labels

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.

[BUG] cudaErrorIllegalAddress when doing pl.concat([filter, filter]).sort().collect() when all filter expressions evaluate to 0 rows

3 participants