Skip to content

Commit

Permalink
DOC: Add comments for the single level groupby
Browse files Browse the repository at this point in the history
  • Loading branch information
Licht-T committed Sep 27, 2017
1 parent ebf8bc3 commit e4cdd07
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pandas/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -2586,14 +2586,17 @@ def _get_grouper(obj, key=None, axis=0, level=None, sort=True,
"""
group_axis = obj._get_axis(axis)

# validate that the passed level is compatible with the passed
# validate that the passed single level is compatible with the passed
# axis of the object
if level is not None:
# TODO: These two conditions are almost same.
# We should combine two.
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):
# Get the level values from group_axis
key = group_axis.get_level_values(level)
level = None

Expand All @@ -2619,6 +2622,8 @@ def _get_grouper(obj, key=None, axis=0, level=None, sort=True,
raise ValueError('level > 0 or level < -1 only valid with '
' MultiIndex')

# NOTE: `group_axis` and `group_axis.get_level_values(level)`
# are same in this section.
level = None
key = group_axis

Expand Down

0 comments on commit e4cdd07

Please sign in to comment.