Skip to content

Fix deprecation warning in SeriesGroupBy.count #22155

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

Merged
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
4 changes: 3 additions & 1 deletion pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
from pandas.core.index import Index, MultiIndex, CategoricalIndex
from pandas.core.arrays.categorical import Categorical
from pandas.core.internals import BlockManager, make_block
from pandas.compat.numpy import _np_version_under1p13

from pandas.plotting._core import boxplot_frame_groupby

Expand Down Expand Up @@ -1207,7 +1208,8 @@ def count(self):

mask = (ids != -1) & ~isna(val)
ids = ensure_platform_int(ids)
out = np.bincount(ids[mask], minlength=ngroups or None)
minlength = ngroups or (None if _np_version_under1p13 else 0)
out = np.bincount(ids[mask], minlength=minlength)

return Series(out,
index=self.grouper.result_index,
Expand Down