Skip to content

Commit fb52c1c

Browse files
Added whatsnew; checked match_axis_length
1 parent 99ebc4e commit fb52c1c

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

doc/source/whatsnew/v0.21.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,7 @@ Groupby/Resample/Rolling
10941094
- Bug in ``DataFrame.groupby`` where a single level selection from a ``MultiIndex`` unexpectedly sorts (:issue:`17537`)
10951095
- Bug in ``DataFrame.groupby`` where spurious warning is raised when ``Grouper`` object is used to override ambiguous column name (:issue:`17383`)
10961096
- Bug in ``TimeGrouper`` differs when passes as a list and as a scalar (:issue:`17530`)
1097+
- Bug in ``DataFrame.groupby`` where key as tuple in a ``MultiIndex`` were interpreted as a list of keys (:issue:`17979`)
10971098

10981099
Sparse
10991100
^^^^^^

pandas/core/groupby.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -2765,14 +2765,13 @@ def _get_grouper(obj, key=None, axis=0, level=None, sort=True,
27652765
elif isinstance(key, BaseGrouper):
27662766
return key, [], obj
27672767

2768-
if not isinstance(key, (tuple, list)):
2768+
# when MultiIndex, allow tuple to be a key
2769+
if not isinstance(key, (tuple, list)) or isinstance(key, tuple) and \
2770+
isinstance(obj._info_axis, MultiIndex):
27692771
keys = [key]
27702772
match_axis_length = False
27712773
else:
2772-
if isinstance(key, tuple) and isinstance(obj._info_axis, MultiIndex):
2773-
keys = [key]
2774-
else:
2775-
keys = key
2774+
keys = key
27762775
match_axis_length = len(keys) == len(group_axis)
27772776

27782777
# what are we after, exactly?

0 commit comments

Comments
 (0)