Skip to content

Commit c52b2a8

Browse files
Moved notes to 0.22; created is_axis_multiindex var - pending internal use
1 parent fb52c1c commit c52b2a8

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

doc/source/whatsnew/v0.21.0.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,6 @@ 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`)
10981097

10991098
Sparse
11001099
^^^^^^

doc/source/whatsnew/v0.22.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ Bug Fixes
8888
~~~~~~~~~
8989

9090
- Bug in ``pd.read_msgpack()`` with a non existent file is passed in Python 2 (:issue:`15296`)
91+
- Bug in ``DataFrame.groupby`` where key as tuple in a ``MultiIndex`` were interpreted as a list of keys (:issue:`17979`)
9192

9293
Conversion
9394
^^^^^^^^^^

pandas/core/groupby.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -2705,6 +2705,7 @@ def _get_grouper(obj, key=None, axis=0, level=None, sort=True,
27052705
27062706
"""
27072707
group_axis = obj._get_axis(axis)
2708+
is_axis_multiindex = isinstance(obj._info_axis, MultiIndex)
27082709

27092710
# validate that the passed single level is compatible with the passed
27102711
# axis of the object
@@ -2766,8 +2767,8 @@ def _get_grouper(obj, key=None, axis=0, level=None, sort=True,
27662767
return key, [], obj
27672768

27682769
# 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):
2770+
if not isinstance(key, (tuple, list)) or \
2771+
(isinstance(key, tuple) and is_axis_multiindex):
27712772
keys = [key]
27722773
match_axis_length = False
27732774
else:
@@ -2871,7 +2872,6 @@ def is_in_obj(gpr):
28712872

28722873
# create the internals grouper
28732874
grouper = BaseGrouper(group_axis, groupings, sort=sort, mutated=mutated)
2874-
28752875
return grouper, exclusions, obj
28762876

28772877

0 commit comments

Comments
 (0)