Skip to content

Commit

Permalink
BUG: Change the location of the checking a single-level selection fro…
Browse files Browse the repository at this point in the history
…m MultiIndex
  • Loading branch information
Licht-T committed Sep 27, 2017
1 parent baae6c3 commit ebf8bc3
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions pandas/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -2586,19 +2586,18 @@ 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:
if not isinstance(group_axis, MultiIndex):
if isinstance(group_axis, MultiIndex):
if is_list_like(level) and len(level) == 1:
level = level[0]

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

else:
# allow level to be a length-one list-like object
# (e.g., level=[0])
# GH 13901
Expand Down

0 comments on commit ebf8bc3

Please sign in to comment.