Skip to content

Commit

Permalink
Fix an error with groupby value_counts for pandas 2.0 compatibi…
Browse files Browse the repository at this point in the history
…lity (#9928)
  • Loading branch information
j-bennet committed Feb 13, 2023
1 parent 1a3f248 commit fe52c0d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion dask/dataframe/groupby.py
Expand Up @@ -1520,6 +1520,7 @@ def _single_agg(
shuffle=None,
chunk_kwargs=None,
aggregate_kwargs=None,
columns=None,
):
"""
Aggregation with a single function/aggfunc rather than a compound spec
Expand All @@ -1543,7 +1544,9 @@ def _single_agg(
with check_numeric_only_deprecation():
meta = func(self._meta_nonempty, **chunk_kwargs)

columns = meta.name if is_series_like(meta) else meta.columns
if columns is None:
columns = meta.name if is_series_like(meta) else meta.columns

args = [self.obj] + (self.by if isinstance(self.by, list) else [self.by])

token = self._token_prefix + token
Expand Down Expand Up @@ -2954,6 +2957,10 @@ def value_counts(self, split_every=None, split_out=1, shuffle=None):
split_every=split_every,
split_out=split_out,
shuffle=shuffle,
# in pandas 2.0, Series returned from value_counts have a name
# different from original object, but here, column name should
# still reflect the original object name
columns=self._meta.apply(pd.Series).name,
)

@derived_from(pd.core.groupby.SeriesGroupBy)
Expand Down

0 comments on commit fe52c0d

Please sign in to comment.