Skip to content

Commit 201a4fe

Browse files
committed
BUG: Never interpret a tuple as a list of keys
1 parent 96a5274 commit 201a4fe

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

doc/source/whatsnew/v0.22.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ Indexing
9999
^^^^^^^^
100100

101101
- Bug in :func:`Series.truncate` which raises ``TypeError`` with a monotonic ``PeriodIndex`` (:issue:`17717`)
102-
- Bug in :func:`DataFrame.groupby` where key as tuple in a ``MultiIndex`` were interpreted as a list of keys (:issue:`17979`)
102+
- Bug in :func:`DataFrame.groupby` where tuples were interpreted as lists of keys rather than as keys (:issue:`17979`)
103103
-
104104
-
105105

pandas/core/groupby.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -2704,7 +2704,6 @@ def _get_grouper(obj, key=None, axis=0, level=None, sort=True,
27042704
27052705
"""
27062706
group_axis = obj._get_axis(axis)
2707-
is_axis_multiindex = isinstance(obj._info_axis, MultiIndex)
27082707

27092708
# validate that the passed single level is compatible with the passed
27102709
# axis of the object
@@ -2765,9 +2764,8 @@ def _get_grouper(obj, key=None, axis=0, level=None, sort=True,
27652764
elif isinstance(key, BaseGrouper):
27662765
return key, [], obj
27672766

2768-
# when MultiIndex, allow tuple to be a key
2769-
if not isinstance(key, (tuple, list)) or \
2770-
(isinstance(key, tuple) and is_axis_multiindex):
2767+
# Everything which is not a list is a key (including tuples):
2768+
if not isinstance(key, list):
27712769
keys = [key]
27722770
match_axis_length = False
27732771
else:

0 commit comments

Comments
 (0)