Skip to content

Commit

Permalink
BUG: Put the checking a single-level selection from MultiIndex higher
Browse files Browse the repository at this point in the history
  • Loading branch information
Licht-T committed Sep 22, 2017
1 parent f797a9e commit 24409e9
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions pandas/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -2586,6 +2586,15 @@ def _get_grouper(obj, key=None, axis=0, level=None, sort=True,
"""
group_axis = obj._get_axis(axis)

if key is None and level is not None and \
isinstance(group_axis, MultiIndex):
if is_list_like(level) and len(level) == 1:
level = level[0]

if is_scalar(level):
key = group_axis.get_level_values(level)
level = None

# validate that the passed level is compatible with the passed
# axis of the object
if level is not None:
Expand Down Expand Up @@ -2626,14 +2635,6 @@ def _get_grouper(obj, key=None, axis=0, level=None, sort=True,
elif isinstance(key, BaseGrouper):
return key, [], obj

if key is None and isinstance(group_axis, MultiIndex):
if is_list_like(level) and len(level) == 1:
level = level[0]

if level is not None and is_scalar(level):
key = group_axis.get_level_values(level)
level = None

if not isinstance(key, (tuple, list)):
keys = [key]
match_axis_length = False
Expand Down

0 comments on commit 24409e9

Please sign in to comment.