Skip to content

Commit 8b185b4

Browse files
committed
PEP
1 parent 781b9b3 commit 8b185b4

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
@@ -1130,8 +1130,8 @@ def size(self):
11301130
def _add_numeric_operations(cls):
11311131
""" add numeric operations to the GroupBy generically """
11321132

1133-
def _groupby_function(name, alias, npfunc,
1134-
numeric_only=True, _convert=False):
1133+
def groupby_function(name, alias, npfunc,
1134+
numeric_only=True, _convert=False):
11351135

11361136
_local_template = "Compute %(f)s of group values"
11371137

@@ -1143,11 +1143,13 @@ def f(self, **kwargs):
11431143
kwargs['numeric_only'] = numeric_only
11441144
self._set_group_selection()
11451145
try:
1146-
return self._cython_agg_general(alias, alt=npfunc, **kwargs)
1146+
return self._cython_agg_general(
1147+
alias, alt=npfunc, **kwargs)
11471148
except AssertionError as e:
11481149
raise SpecificationError(str(e))
11491150
except Exception:
1150-
result = self.aggregate(lambda x: npfunc(x, axis=self.axis))
1151+
result = self.aggregate(
1152+
lambda x: npfunc(x, axis=self.axis))
11511153
if _convert:
11521154
result = result._convert(datetime=True)
11531155
return result
@@ -1156,9 +1158,9 @@ def f(self, **kwargs):
11561158

11571159
return f
11581160

1159-
def _first_compat(x, axis=0):
1161+
def first_compat(x, axis=0):
11601162

1161-
def _first(x):
1163+
def first(x):
11621164

11631165
x = np.asarray(x)
11641166
x = x[notnull(x)]
@@ -1167,13 +1169,13 @@ def _first(x):
11671169
return x[0]
11681170

11691171
if isinstance(x, DataFrame):
1170-
return x.apply(_first, axis=axis)
1172+
return x.apply(first, axis=axis)
11711173
else:
1172-
return _first(x)
1174+
return first(x)
11731175

1176+
def last_compat(x, axis=0):
11741177

1175-
def _last_compat(x, axis=0):
1176-
def _last(x):
1178+
def last(x):
11771179

11781180
x = np.asarray(x)
11791181
x = x[notnull(x)]
@@ -1182,18 +1184,18 @@ def _last(x):
11821184
return x[-1]
11831185

11841186
if isinstance(x, DataFrame):
1185-
return x.apply(_last, axis=axis)
1187+
return x.apply(last, axis=axis)
11861188
else:
1187-
return _last(x)
1189+
return last(x)
11881190

1189-
cls.sum = _groupby_function('sum', 'add', np.sum)
1190-
cls.prod = _groupby_function('prod', 'prod', np.prod)
1191-
cls.min = _groupby_function('min', 'min', np.min, numeric_only=False)
1192-
cls.max = _groupby_function('max', 'max', np.max, numeric_only=False)
1193-
cls.first = _groupby_function('first', 'first', _first_compat,
1194-
numeric_only=False, _convert=True)
1195-
cls.last = _groupby_function('last', 'last', _last_compat, numeric_only=False,
1196-
_convert=True)
1191+
cls.sum = groupby_function('sum', 'add', np.sum)
1192+
cls.prod = groupby_function('prod', 'prod', np.prod)
1193+
cls.min = groupby_function('min', 'min', np.min, numeric_only=False)
1194+
cls.max = groupby_function('max', 'max', np.max, numeric_only=False)
1195+
cls.first = groupby_function('first', 'first', first_compat,
1196+
numeric_only=False, _convert=True)
1197+
cls.last = groupby_function('last', 'last', last_compat,
1198+
numeric_only=False, _convert=True)
11971199

11981200
@Substitution(name='groupby')
11991201
@Appender(_doc_template)
@@ -1605,6 +1607,7 @@ def tail(self, n=5):
16051607
mask = self._cumcount_array(ascending=False) < n
16061608
return self._selected_obj[mask]
16071609

1610+
16081611
GroupBy._add_numeric_operations()
16091612

16101613

0 commit comments

Comments
 (0)