Skip to content

Handle empty aggregations in multi-partition cudf.polars group_by #18277

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 1 commit into from
May 9, 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
17 changes: 8 additions & 9 deletions python/cudf_polars/cudf_polars/dsl/utils/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

from typing import TYPE_CHECKING

import pylibcudf as plc

from cudf_polars.dsl import ir
from cudf_polars.dsl.utils.aggregations import apply_pre_evaluation
from cudf_polars.dsl.utils.naming import unique_names
Expand All @@ -15,8 +17,6 @@
from collections.abc import Sequence
from typing import Any

import pylibcudf as plc

from cudf_polars.dsl import expr
from cudf_polars.utils import config

Expand Down Expand Up @@ -71,16 +71,15 @@ def rewrite_groupby(
unsupported.
"""
if len(aggs) == 0:
# TODO: use Distinct when the partitioned executor supports it
return ir.GroupBy(
return ir.Distinct(
schema,
keys,
[],
node.maintain_order,
plc.stream_compaction.DuplicateKeepOption.KEEP_ANY,
None,
node.options.slice,
config_options,
inp,
node.maintain_order,
ir.Select(schema, keys, True, inp), # noqa: FBT003
)

inp, aggs, group_schema, apply_post_evaluation = apply_pre_evaluation(
schema, inp, keys, aggs, unique_names(schema.keys())
)
Expand Down
5 changes: 5 additions & 0 deletions python/cudf_polars/tests/experimental/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,8 @@ def test_groupby_agg_duplicate(
)
q = df.group_by("y").agg(op, pl.min(column_name))
assert_gpu_result_equal(q, engine=engine, check_row_order=False)


def test_groupby_agg_empty(df: pl.LazyFrame, engine: pl.GPUEngine) -> None:
q = df.group_by("y").agg()
assert_gpu_result_equal(q, engine=engine, check_row_order=False)
Loading