From e4cdd0726e685b0216056ba224ed363bf1e836f9 Mon Sep 17 00:00:00 2001 From: Licht-T Date: Wed, 27 Sep 2017 20:35:09 +0900 Subject: [PATCH] DOC: Add comments for the single level groupby --- pandas/core/groupby.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pandas/core/groupby.py b/pandas/core/groupby.py index dd1174223752a8..830320ac077bcd 100644 --- a/pandas/core/groupby.py +++ b/pandas/core/groupby.py @@ -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 @@ -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