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

Return a Series from JIT GroupBy apply, rather than a DataFrame #13820

Merged
merged 5 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 1 addition & 2 deletions python/cudf/cudf/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -1204,8 +1204,7 @@ def _jit_groupby_apply(
{None: chunk_results}, index=group_names
)
result.index.names = self.grouping.names
result = result.reset_index()
result[None] = result.pop(0)

return result

@_cudf_nvtx_annotate
Expand Down
31 changes: 17 additions & 14 deletions python/cudf/cudf/tests/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ def groupby_jit_data():


def run_groupby_apply_jit_test(data, func, keys, *args):
expect_groupby_obj = data.to_pandas().groupby(keys, as_index=False)
expect_groupby_obj = data.to_pandas().groupby(keys)
got_groupby_obj = data.groupby(keys)

# compare cuDF jit to pandas
Expand Down Expand Up @@ -475,7 +475,19 @@ def func(df):

@pytest.mark.parametrize("dtype", ["float64"])
@pytest.mark.parametrize("func", ["idxmax", "idxmin"])
@pytest.mark.parametrize("special_val", [np.nan, np.inf, -np.inf])
@pytest.mark.parametrize(
"special_val",
[
pytest.param(
np.nan,
marks=pytest.mark.xfail(
reason="https://github.com/rapidsai/cudf/issues/13832"
),
),
np.inf,
-np.inf,
],
)
def test_groupby_apply_jit_idx_reductions_special_vals(
func, groupby_jit_data, dtype, special_val
):
Expand All @@ -494,19 +506,10 @@ def func(df):
groupby_jit_data["val1"] = special_val
groupby_jit_data["val1"] = groupby_jit_data["val1"].astype(dtype)

expect = (
groupby_jit_data.to_pandas()
.groupby("key1", as_index=False)
.apply(func)
)

grouped = groupby_jit_data.groupby("key1")
sorted = grouped._grouped()[3].to_pandas()
expect_vals = sorted["key1"].drop_duplicates().index
expect[None] = expect_vals
expect = groupby_jit_data.to_pandas().groupby("key1").apply(func)
got = groupby_jit_data.groupby("key1").apply(func, engine="jit")

got = grouped.apply(func, engine="jit")
assert_eq(expect, got)
assert_eq(expect, got, check_dtype=False)


@pytest.mark.parametrize(
Expand Down