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 value_counts with split_out != 1 #1170

Merged
merged 2 commits into from
Nov 19, 2024
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
3 changes: 2 additions & 1 deletion dask_expr/_reductions.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ def _lower(self):

# Reset the index if we we used it for shuffling
if split_by_index:
shuffled = SetIndexBlockwise(shuffled, split_by, True, None)
idx = list(self._meta.index.names) if split_by != ["index"] else split_by
shuffled = SetIndexBlockwise(shuffled, idx, True, None)

# Convert back to Series if necessary
if self.shuffle_by_index is not False:
Expand Down
7 changes: 7 additions & 0 deletions dask_expr/tests/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ def test_groupby_no_numeric_only(pdf, func):
assert_eq(agg, expect)


def test_value_counts_split_out(pdf):
df = from_pandas(pdf, npartitions=10)
result = df.groupby("x").y.value_counts(split_out=True)
expected = pdf.groupby("x").y.value_counts()
assert_eq(result, expected)


def test_unique(df, pdf):
result = df.groupby("x")["y"].unique()
expected = pdf.groupby("x")["y"].unique()
Expand Down
Loading