Skip to content

Commit f17f13b

Browse files
committed
PEP
1 parent 92a1da6 commit f17f13b

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

pandas/core/groupby.py

+23-20
Original file line numberDiff line numberDiff line change
@@ -1112,8 +1112,8 @@ def size(self):
11121112
def _add_numeric_operations(cls):
11131113
""" add numeric operations to the GroupBy generically """
11141114

1115-
def _groupby_function(name, alias, npfunc,
1116-
numeric_only=True, _convert=False):
1115+
def groupby_function(name, alias, npfunc,
1116+
numeric_only=True, _convert=False):
11171117

11181118
_local_template = "Compute %(f)s of group values"
11191119

@@ -1125,11 +1125,13 @@ def f(self, **kwargs):
11251125
kwargs['numeric_only'] = numeric_only
11261126
self._set_group_selection()
11271127
try:
1128-
return self._cython_agg_general(alias, alt=npfunc, **kwargs)
1128+
return self._cython_agg_general(
1129+
alias, alt=npfunc, **kwargs)
11291130
except AssertionError as e:
11301131
raise SpecificationError(str(e))
11311132
except Exception:
1132-
result = self.aggregate(lambda x: npfunc(x, axis=self.axis))
1133+
result = self.aggregate(
1134+
lambda x: npfunc(x, axis=self.axis))
11331135
if _convert:
11341136
result = result._convert(datetime=True)
11351137
return result
@@ -1138,9 +1140,9 @@ def f(self, **kwargs):
11381140

11391141
return f
11401142

1141-
def _first_compat(x, axis=0):
1143+
def first_compat(x, axis=0):
11421144

1143-
def _first(x):
1145+
def first(x):
11441146

11451147
x = np.asarray(x)
11461148
x = x[notnull(x)]
@@ -1149,13 +1151,13 @@ def _first(x):
11491151
return x[0]
11501152

11511153
if isinstance(x, DataFrame):
1152-
return x.apply(_first, axis=axis)
1154+
return x.apply(first, axis=axis)
11531155
else:
1154-
return _first(x)
1156+
return first(x)
11551157

1158+
def last_compat(x, axis=0):
11561159

1157-
def _last_compat(x, axis=0):
1158-
def _last(x):
1160+
def last(x):
11591161

11601162
x = np.asarray(x)
11611163
x = x[notnull(x)]
@@ -1164,18 +1166,18 @@ def _last(x):
11641166
return x[-1]
11651167

11661168
if isinstance(x, DataFrame):
1167-
return x.apply(_last, axis=axis)
1169+
return x.apply(last, axis=axis)
11681170
else:
1169-
return _last(x)
1171+
return last(x)
11701172

1171-
cls.sum = _groupby_function('sum', 'add', np.sum)
1172-
cls.prod = _groupby_function('prod', 'prod', np.prod)
1173-
cls.min = _groupby_function('min', 'min', np.min, numeric_only=False)
1174-
cls.max = _groupby_function('max', 'max', np.max, numeric_only=False)
1175-
cls.first = _groupby_function('first', 'first', _first_compat,
1176-
numeric_only=False, _convert=True)
1177-
cls.last = _groupby_function('last', 'last', _last_compat, numeric_only=False,
1178-
_convert=True)
1173+
cls.sum = groupby_function('sum', 'add', np.sum)
1174+
cls.prod = groupby_function('prod', 'prod', np.prod)
1175+
cls.min = groupby_function('min', 'min', np.min, numeric_only=False)
1176+
cls.max = groupby_function('max', 'max', np.max, numeric_only=False)
1177+
cls.first = groupby_function('first', 'first', first_compat,
1178+
numeric_only=False, _convert=True)
1179+
cls.last = groupby_function('last', 'last', last_compat,
1180+
numeric_only=False, _convert=True)
11791181

11801182
@Substitution(name='groupby')
11811183
@Appender(_doc_template)
@@ -1587,6 +1589,7 @@ def tail(self, n=5):
15871589
mask = self._cumcount_array(ascending=False) < n
15881590
return self._selected_obj[mask]
15891591

1592+
15901593
GroupBy._add_numeric_operations()
15911594

15921595

0 commit comments

Comments
 (0)