Skip to content

ENH: Add DataFrameGroupBy.value_counts #44267

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 140 commits into from
Dec 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
140 commits
Select commit Hold shift + click to select a range
963b7e1
Add DataFrameGroupBy.value_counts
johnzangwill Nov 1, 2021
1f710e0
Update test_frame_value_counts.py
johnzangwill Nov 1, 2021
3531383
Catch axis=1
johnzangwill Nov 1, 2021
d7f733b
Add to base and tab_completion
johnzangwill Nov 1, 2021
eb067ec
Line too long
johnzangwill Nov 1, 2021
a6a07d1
Update test_frame_value_counts.py
johnzangwill Nov 1, 2021
6a22a57
Add docstring
johnzangwill Nov 1, 2021
9492ee4
Update generic.py
johnzangwill Nov 1, 2021
b9885fd
Update groupby.rst
johnzangwill Nov 1, 2021
e896879
generic.py types
johnzangwill Nov 1, 2021
6de9653
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Nov 1, 2021
5b49322
Add observed parameter
johnzangwill Nov 1, 2021
651b20b
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Nov 1, 2021
26353ee
Change output name to "count" and deal with categorical data
johnzangwill Nov 3, 2021
9f44a6d
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Nov 3, 2021
0e065b3
Update generic.py
johnzangwill Nov 3, 2021
b821fca
Add test_categorical
johnzangwill Nov 3, 2021
19d7257
Update test_frame_value_counts.py
johnzangwill Nov 3, 2021
71ee5f4
Add by=function test
johnzangwill Nov 3, 2021
1dd2db0
Update test_frame_value_counts.py
johnzangwill Nov 3, 2021
1c18d7d
Update test_frame_value_counts.py
johnzangwill Nov 3, 2021
f25e861
Update generic.py
johnzangwill Nov 3, 2021
faac0f0
Update test_frame_value_counts.py
johnzangwill Nov 3, 2021
3934042
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Nov 4, 2021
4904c31
Merge branch 'master' into DataFrameGroupBy.value_counts
johnzangwill Nov 5, 2021
0f615da
Update v1.4.0.rst
johnzangwill Nov 5, 2021
c2db74f
Merge branch 'master' into DataFrameGroupBy.value_counts
johnzangwill Nov 6, 2021
ba793bb
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Nov 6, 2021
221b76a
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Nov 7, 2021
424d7a6
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Nov 9, 2021
5216929
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Nov 12, 2021
50d4c59
Reset index after sorting
johnzangwill Nov 14, 2021
9b2869f
Toughen up testing for groupers in keys
johnzangwill Nov 14, 2021
3de6132
De-numpy most of the tests
johnzangwill Nov 14, 2021
a9c2b83
Update test_frame_value_counts.py
johnzangwill Nov 15, 2021
0ad5ffb
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Nov 15, 2021
6905bcd
Better detection of non-column grouping
johnzangwill Nov 15, 2021
0281539
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Nov 15, 2021
eb9600f
Finish de-numpying the tests
johnzangwill Nov 15, 2021
f529714
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Nov 15, 2021
0ae5218
Dropna changes
johnzangwill Nov 15, 2021
15e3167
Merge branch 'DataFrameGroupBy.value_counts' of https://github.com/jo…
johnzangwill Nov 15, 2021
dfa82cb
Update generic.py
johnzangwill Nov 15, 2021
6e2b06e
Add bad subset trap and test
johnzangwill Nov 15, 2021
2dc5972
Update generic.py
johnzangwill Nov 15, 2021
925d3ec
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Nov 16, 2021
82730f1
Merge branch 'master' into DataFrameGroupBy.value_counts
johnzangwill Nov 17, 2021
d7b3149
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Nov 17, 2021
8d8d9b0
Add more dropna tests and workaround Series bug
johnzangwill Nov 20, 2021
c12d831
Merge branch 'DataFrameGroupBy.value_counts' of https://github.com/jo…
johnzangwill Nov 20, 2021
57d3fb8
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Nov 20, 2021
c431953
Reformat
johnzangwill Nov 20, 2021
4d10e47
Update generic.py
johnzangwill Nov 20, 2021
e4582ef
Typing fix
johnzangwill Nov 21, 2021
c948274
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Nov 21, 2021
2a58c42
Update generic.py
johnzangwill Nov 21, 2021
e1596b1
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Nov 22, 2021
df76279
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Nov 22, 2021
04ebe65
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Nov 22, 2021
f179fbb
Update test_frame_value_counts.py
johnzangwill Nov 22, 2021
98355d5
Replace self.as_index==False code with reset_index()
johnzangwill Nov 23, 2021
0be0150
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Nov 23, 2021
25edd1e
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Nov 23, 2021
97ab9c1
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Nov 23, 2021
6ac9356
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Nov 24, 2021
45b99af
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Nov 24, 2021
0cbb3e2
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Nov 25, 2021
fada9a9
Remove Series name and change column name
johnzangwill Nov 25, 2021
8e3f359
Change non_column_grouping
johnzangwill Nov 25, 2021
ca15937
Update test_frame_value_counts.py
johnzangwill Nov 25, 2021
f055323
Update generic.py
johnzangwill Nov 25, 2021
417958d
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Nov 25, 2021
86a0df6
Correct docstring example
johnzangwill Nov 26, 2021
7d29bd4
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Nov 26, 2021
32f4b6f
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Nov 26, 2021
c13eef0
Improve bad subset message
johnzangwill Nov 26, 2021
2c2eb0a
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Nov 26, 2021
7638086
Update generic.py
johnzangwill Nov 28, 2021
57b564b
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Nov 28, 2021
aa3cb98
Update generic.py
johnzangwill Nov 28, 2021
5e5d7e7
Update generic.py
johnzangwill Nov 28, 2021
09cee2f
Add mixed grouping test
johnzangwill Nov 29, 2021
5838066
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Nov 29, 2021
8f81bd2
Trigger CI
johnzangwill Nov 29, 2021
92cb494
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Nov 29, 2021
95ccdb4
Trigger CI
johnzangwill Nov 29, 2021
085e8c9
Some refinements
rhshadrach Nov 30, 2021
9fcfbfe
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Nov 30, 2021
bb5f82a
Trigger CI
johnzangwill Nov 30, 2021
377cee0
Merge branch 'DataFrameGroupBy.value_counts' of https://github.com/jo…
johnzangwill Nov 30, 2021
c824f3e
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Dec 2, 2021
92c718b
Merge pull request #5 from rhshadrach/DataFrameGroupBy.value_counts
johnzangwill Dec 2, 2021
14d8172
Add test_column_name_clashes
johnzangwill Dec 2, 2021
e26cba1
Update test_frame_value_counts.py
johnzangwill Dec 2, 2021
928a9d7
Update test_frame_value_counts.py
johnzangwill Dec 2, 2021
ad0f5b4
Trigger CI
johnzangwill Dec 2, 2021
e827cd3
Trigger CI
johnzangwill Dec 2, 2021
2c2b967
reset_index to cope with duplicate labels
johnzangwill Dec 3, 2021
51a3a3e
Update frame.py
johnzangwill Dec 3, 2021
2ee133e
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Dec 3, 2021
ec2a2d4
Update test_put.py
johnzangwill Dec 3, 2021
9d330d1
Merge branch 'DataFrameGroupBy.value_counts' of https://github.com/jo…
johnzangwill Dec 3, 2021
8e4f3ed
Comment out tests that now pass
johnzangwill Dec 3, 2021
b2c61de
Update test_reset_index.py
johnzangwill Dec 3, 2021
392986d
Trigger CI
johnzangwill Dec 3, 2021
3b2ac58
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Dec 4, 2021
34e6529
Update generic.py
johnzangwill Dec 4, 2021
91e1ff3
Update test_reset_index.py
johnzangwill Dec 4, 2021
06aaaeb
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Dec 5, 2021
e062823
Improve test imports
johnzangwill Dec 5, 2021
a8b0fc5
Merge branch 'DataFrameGroupBy.value_counts' of https://github.com/jo…
johnzangwill Dec 5, 2021
493e3aa
Update test_frame_value_counts.py
johnzangwill Dec 5, 2021
548c45b
Update test_frame_value_counts.py
johnzangwill Dec 5, 2021
6c19ce2
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Dec 5, 2021
6141f85
Revert changes to reset_index()
johnzangwill Dec 6, 2021
050f070
Update frame.py
johnzangwill Dec 6, 2021
d669af3
Add reset_index failure to test
johnzangwill Dec 6, 2021
6c0d7f8
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Dec 6, 2021
de68836
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Dec 8, 2021
c81adb6
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Dec 10, 2021
08fd6ab
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Dec 10, 2021
dc67009
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Dec 10, 2021
d023579
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Dec 11, 2021
71d9780
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Dec 11, 2021
b93f47c
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Dec 11, 2021
db31257
Add grouping test
johnzangwill Dec 12, 2021
124b1e9
Trigger CI
johnzangwill Dec 12, 2021
d613261
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Dec 14, 2021
a776a3d
Trigger CI
johnzangwill Dec 14, 2021
4ef5ea0
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Dec 14, 2021
0f0891f
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Dec 15, 2021
5c1d021
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Dec 16, 2021
fe58245
Update generic.py
johnzangwill Dec 17, 2021
11ad6ea
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Dec 17, 2021
857e5be
Update generic.py
johnzangwill Dec 18, 2021
5b9d85a
Merge branch 'DataFrameGroupBy.value_counts' of https://github.com/jo…
johnzangwill Dec 18, 2021
e226547
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Dec 18, 2021
c8f1731
Trigger CI
johnzangwill Dec 18, 2021
8f89580
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Dec 18, 2021
ac38571
Merge branch 'pandas-dev:master' into DataFrameGroupBy.value_counts
johnzangwill Dec 19, 2021
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
1 change: 1 addition & 0 deletions doc/source/reference/groupby.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ application to columns of a specific data type.
DataFrameGroupBy.skew
DataFrameGroupBy.take
DataFrameGroupBy.tshift
DataFrameGroupBy.value_counts

The following methods are available only for ``SeriesGroupBy`` objects.

Expand Down
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.4.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ Other enhancements
- Added :meth:`.ExponentialMovingWindow.sum` (:issue:`13297`)
- :meth:`Series.str.split` now supports a ``regex`` argument that explicitly specifies whether the pattern is a regular expression. Default is ``None`` (:issue:`43563`, :issue:`32835`, :issue:`25549`)
- :meth:`DataFrame.dropna` now accepts a single label as ``subset`` along with array-like (:issue:`41021`)
- Added :meth:`DataFrameGroupBy.value_counts` (:issue:`43564`)
- :class:`ExcelWriter` argument ``if_sheet_exists="overlay"`` option added (:issue:`40231`)
- :meth:`read_excel` now accepts a ``decimal`` argument that allow the user to specify the decimal point when parsing string columns to numeric (:issue:`14403`)
- :meth:`.GroupBy.mean`, :meth:`.GroupBy.std`, and :meth:`.GroupBy.var` now supports `Numba <http://numba.pydata.org/>`_ execution with the ``engine`` keyword (:issue:`43731`, :issue:`44862`)
Expand Down
1 change: 1 addition & 0 deletions pandas/core/groupby/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ class OutputKey:
"take",
"transform",
"sample",
"value_counts",
]
)
# Valid values of `name` for `groupby.transform(name)`
Expand Down
189 changes: 189 additions & 0 deletions pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
Iterable,
Mapping,
NamedTuple,
Sequence,
TypeVar,
Union,
cast,
Expand Down Expand Up @@ -76,6 +77,7 @@
_transform_template,
warn_dropping_nuisance_columns_deprecated,
)
from pandas.core.groupby.grouper import get_grouper
from pandas.core.indexes.api import (
Index,
MultiIndex,
Expand Down Expand Up @@ -1569,6 +1571,193 @@ def func(df):

boxplot = boxplot_frame_groupby

def value_counts(
self,
subset: Sequence[Hashable] | None = None,
normalize: bool = False,
sort: bool = True,
ascending: bool = False,
dropna: bool = True,
) -> DataFrame | Series:
"""
Return a Series or DataFrame containing counts of unique rows.

.. versionadded:: 1.4.0

Parameters
----------
subset : list-like, optional
Columns to use when counting unique combinations.
normalize : bool, default False
Return proportions rather than frequencies.
sort : bool, default True
Sort by frequencies.
ascending : bool, default False
Sort in ascending order.
dropna : bool, default True
Don’t include counts of rows that contain NA values.

Returns
-------
Series or DataFrame
Series if the groupby as_index is True, otherwise DataFrame.

See Also
--------
Series.value_counts: Equivalent method on Series.
DataFrame.value_counts: Equivalent method on DataFrame.
SeriesGroupBy.value_counts: Equivalent method on SeriesGroupBy.

Notes
-----
- If the groupby as_index is True then the returned Series will have a
MultiIndex with one level per input column.
- If the groupby as_index is False then the returned DataFrame will have an
additional column with the value_counts. The column is labelled 'count' or
'proportion', depending on the ``normalize`` parameter.

By default, rows that contain any NA values are omitted from
the result.

By default, the result will be in descending order so that the
first element of each group is the most frequently-occurring row.

Examples
--------
>>> df = pd.DataFrame({
... 'gender': ['male', 'male', 'female', 'male', 'female', 'male'],
... 'education': ['low', 'medium', 'high', 'low', 'high', 'low'],
... 'country': ['US', 'FR', 'US', 'FR', 'FR', 'FR']
... })

>>> df
gender education country
0 male low US
1 male medium FR
2 female high US
3 male low FR
4 female high FR
5 male low FR

>>> df.groupby('gender').value_counts()
gender education country
female high FR 1
US 1
male low FR 2
US 1
medium FR 1
dtype: int64

>>> df.groupby('gender').value_counts(ascending=True)
gender education country
female high FR 1
US 1
male low US 1
medium FR 1
low FR 2
dtype: int64

>>> df.groupby('gender').value_counts(normalize=True)
gender education country
female high FR 0.50
US 0.50
male low FR 0.50
US 0.25
medium FR 0.25
dtype: float64

>>> df.groupby('gender', as_index=False).value_counts()
gender education country count
0 female high FR 1
1 female high US 1
2 male low FR 2
3 male low US 1
4 male medium FR 1

>>> df.groupby('gender', as_index=False).value_counts(normalize=True)
gender education country proportion
0 female high FR 0.50
1 female high US 0.50
2 male low FR 0.50
3 male low US 0.25
4 male medium FR 0.25
"""
if self.axis == 1:
raise NotImplementedError(
"DataFrameGroupBy.value_counts only handles axis=0"
)

with self._group_selection_context():
df = self.obj

in_axis_names = {
grouping.name for grouping in self.grouper.groupings if grouping.in_axis
}
if isinstance(self._selected_obj, Series):
name = self._selected_obj.name
keys = [] if name in in_axis_names else [self._selected_obj]
else:
keys = [
# Can't use .values because the column label needs to be preserved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you not just do column selection? e.g. []

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Member

@rhshadrach rhshadrach Dec 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Column selection would fail if there are duplicate column labels since these are groupers and must be 1-dimensional (otherwise grouper construction will raise)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok is there a test with duplicates?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test_column_name_clashes

Copy link
Contributor Author

@johnzangwill johnzangwill Dec 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to use positional, to avoid problems with duplicate column labels, and Series, to preserve the label in the grouper.
The test is test_column_name_clashes
In the as_index=False case, this currently detects failure for all inputs. Once I have reset_index(allow_duplicates=True) available then I will make another PR to allow duplicate input column labels through (but not level_n clashes, which I think deserve to fail!)

self._selected_obj.iloc[:, idx]
for idx, name in enumerate(self._selected_obj.columns)
if name not in in_axis_names
]

if subset is not None:
clashing = set(subset) & set(in_axis_names)
if clashing:
raise ValueError(
f"Keys {clashing} in subset cannot be in "
"the groupby column keys"
)

groupings = list(self.grouper.groupings)
for key in keys:
grouper, _, _ = get_grouper(
df,
key=key,
axis=self.axis,
sort=self.sort,
dropna=dropna,
)
groupings += list(grouper.groupings)

# Take the size of the overall columns
gb = df.groupby(
groupings,
sort=self.sort,
observed=self.observed,
dropna=self.dropna,
)
result = cast(Series, gb.size())

if normalize:
# Normalize the results by dividing by the original group sizes.
# We are guaranteed to have the first N levels be the
# user-requested grouping.
levels = list(range(len(self.grouper.groupings), result.index.nlevels))
indexed_group_size = result.groupby(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you not use gb here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what's meant by gb (self?), but the idea here is to use the result which is typically smaller than the obj in the groupby. By transforming, the index of indexed_group_size and result are the same, meaning there doesn't need to be alignment and this speeds up the division on L1712 below.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gb is the groupby for size above

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, when grouping by ['a', 'b'] in a DataFrame that has columns ['a', 'b', 'c'], gb will be grouping by all three columns whereas here we only want to group by ['a', 'b'].

Copy link
Contributor Author

@johnzangwill johnzangwill Dec 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each groupby has different options. These ones have the default as_index=True to get Series, whereas self might not have done. Perhaps one could optimize this with a test, but it is pretty fast anyway, and complicated enough!

result.index.droplevel(levels),
sort=self.sort,
observed=self.observed,
dropna=self.dropna,
).transform("sum")

result /= indexed_group_size

if sort:
# Sort the values and then resort by the main grouping
index_level = range(len(self.grouper.groupings))
result = result.sort_values(ascending=ascending).sort_index(
level=index_level, sort_remaining=False
)

if not self.as_index:
# Convert to frame
result = result.reset_index(name="proportion" if normalize else "count")
return result.__finalize__(self.obj, method="value_counts")


def _wrap_transform_general_frame(
obj: DataFrame, group: DataFrame, res: DataFrame | Series
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/groupby/grouper.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ def get_grouper(

# what are we after, exactly?
any_callable = any(callable(g) or isinstance(g, dict) for g in keys)
any_groupers = any(isinstance(g, Grouper) for g in keys)
any_groupers = any(isinstance(g, (Grouper, Grouping)) for g in keys)
any_arraylike = any(
isinstance(g, (list, tuple, Series, Index, np.ndarray)) for g in keys
)
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/groupby/test_allowlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ def test_tab_completion(mframe):
"pipe",
"sample",
"ewm",
"value_counts",
}
assert results == expected

Expand Down
Loading