Skip to content
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

Use a key column rather than a placeholder for count agg #16599

Merged
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
36 changes: 4 additions & 32 deletions python/cudf_polars/cudf_polars/dsl/ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import dataclasses
import itertools
import types
from functools import cache
from pathlib import Path
from typing import TYPE_CHECKING, Any, Callable, ClassVar
Expand Down Expand Up @@ -492,36 +491,6 @@ def evaluate(
return DataFrame(columns)


def placeholder_column(n: int) -> plc.Column:
"""
Produce a placeholder pylibcudf column with NO BACKING DATA.

Parameters
----------
n
Number of rows the column will advertise

Returns
-------
pylibcudf Column that is almost unusable. DO NOT ACCESS THE DATA BUFFER.

Notes
-----
This is used to avoid allocating data for count aggregations.
"""
return plc.Column(
plc.DataType(plc.TypeId.INT8),
n,
plc.gpumemoryview(
types.SimpleNamespace(__cuda_array_interface__={"data": (1, True)})
),
None,
0,
0,
[],
)


@dataclasses.dataclass
class GroupBy(IR):
"""Perform a groupby."""
Expand Down Expand Up @@ -602,7 +571,10 @@ def evaluate(self, *, cache: MutableMapping[int, DataFrame]) -> DataFrame:
for info in self.agg_infos:
for pre_eval, req, rep in info.requests:
if pre_eval is None:
col = placeholder_column(df.num_rows)
# A count aggregation, doesn't touch the column,
# but we need to have one. Rather than evaluating
# one, just use one of the key columns.
col = keys[0].obj
else:
col = pre_eval.evaluate(df).obj
requests.append(plc.groupby.GroupByRequest(col, [req]))
Expand Down
Loading