Skip to content

Fix Literal partitioning in cudf-polars #19160

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 3 commits into from
Jun 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion python/cudf_polars/cudf_polars/experimental/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import pylibcudf as plc

from cudf_polars.dsl import expr
from cudf_polars.dsl.ir import HConcat, Scan, Select, Union
from cudf_polars.dsl.expr import Col, Len
from cudf_polars.dsl.ir import Empty, HConcat, Scan, Select, Union
from cudf_polars.dsl.traversal import traversal
from cudf_polars.experimental.base import PartitionInfo
from cudf_polars.experimental.dispatch import lower_ir_node
Expand Down Expand Up @@ -116,6 +117,7 @@ def _(
and isinstance(child.children[0], Scan)
and child.children[0].predicate is None
):
# Special Case: Fast count.
scan = child.children[0]
count = scan.fast_count()
dtype = ir.exprs[0].value.dtype
Expand All @@ -135,9 +137,18 @@ def _(
partition_info[new_node] = PartitionInfo(count=1)
return new_node, partition_info

if not any(
isinstance(expr, (Col, Len)) for expr in traversal([e.value for e in ir.exprs])
):
# Special Case: Selection does not depend on any columns.
new_node = ir.reconstruct([input_ir := Empty()])
partition_info[input_ir] = partition_info[new_node] = PartitionInfo(count=1)
return new_node, partition_info

if pi.count > 1 and not all(
expr.is_pointwise for expr in traversal([e.value for e in ir.exprs])
):
# Special Case: Multiple partitions with 1+ non-pointwise expressions.
try:
# Try decomposing the underlying expressions
return decompose_select(
Expand Down
7 changes: 7 additions & 0 deletions python/cudf_polars/tests/experimental/test_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,10 @@ def test_select_parquet_fast_count(request, tmp_path, df, engine):
df.collect().write_parquet(file)
q = pl.scan_parquet(file).select(pl.len())
assert_gpu_result_equal(q, engine=engine)


def test_select_literal(engine):
# See: https://github.com/rapidsai/cudf/issues/19147
ldf = pl.LazyFrame({"a": list(range(10))})
q = ldf.select(pl.lit(2).pow(pl.lit(-3, dtype=pl.Float32)))
assert_gpu_result_equal(q, engine=engine)