Skip to content

Commit ec4a3e7

Browse files
Added whatsnew; checked match_axis_length
1 parent f5a7950 commit ec4a3e7

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
@@ -1052,6 +1052,7 @@ Groupby/Resample/Rolling
10521052
- Bug in ``DataFrame.groupby`` where a single level selection from a ``MultiIndex`` unexpectedly sorts (:issue:`17537`)
10531053
- Bug in ``DataFrame.groupby`` where spurious warning is raised when ``Grouper`` object is used to override ambiguous column name (:issue:`17383`)
10541054
- Bug in ``TimeGrouper`` differs when passes as a list and as a scalar (:issue:`17530`)
1055+
- Bug in ``DataFrame.groupby`` where key as tuple in a ``MultiIndex`` were interpreted as a list of keys (:issue:`17979`)
10551056

10561057
Sparse
10571058
^^^^^^

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)