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

Fix Series.groupby.shift with a MultiIndex #15098

Merged
merged 3 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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: 2 additions & 1 deletion python/cudf/cudf/core/multiindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -2037,7 +2037,8 @@ def _copy_type_metadata(
self: MultiIndex, other: MultiIndex, *, override_dtypes=None
) -> MultiIndex:
res = super()._copy_type_metadata(other)
res._names = other._names
if isinstance(other, MultiIndex):
res._names = other._names
return res

@_cudf_nvtx_annotate
Expand Down
11 changes: 10 additions & 1 deletion python/cudf/cudf/tests/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -3308,7 +3308,6 @@ def test_groupby_pct_change(data, gkey, periods, fill_method):
assert_eq(expected, actual)


@pytest.mark.xfail(reason="https://github.com/rapidsai/cudf/issues/11259")
@pytest.mark.parametrize("periods", [-5, 5])
def test_groupby_pct_change_multiindex_dataframe(periods):
gdf = cudf.DataFrame(
Expand Down Expand Up @@ -3812,3 +3811,13 @@ def test_groupby_internal_groups_empty(gdf):
gb = gdf.groupby("y")._groupby
_, _, grouped_vals = gb.groups([])
assert grouped_vals == []


def test_groupby_shift_series_mi():
mroeschke marked this conversation as resolved.
Show resolved Hide resolved
idx = cudf.MultiIndex.from_tuples(
[("a", 1), ("a", 2), ("b", 1), ("b", 2)], names=["f", "s"]
)
ser = Series(range(4), index=idx)
result = ser.groupby(level=0).shift(1)
expected = ser.to_pandas().groupby(level=0).shift(1)
assert_eq(expected, result)
Loading