|
75 | 75 | 'last', 'first',
|
76 | 76 | 'head', 'tail', 'median',
|
77 | 77 | 'mean', 'sum', 'min', 'max',
|
78 |
| - 'cumsum', 'cumprod', 'cummin', 'cummax', 'cumcount', |
| 78 | + 'cumcount', |
79 | 79 | 'resample',
|
80 | 80 | 'describe',
|
81 | 81 | 'rank', 'quantile',
|
|
97 | 97 | _dataframe_apply_whitelist = \
|
98 | 98 | _common_apply_whitelist | frozenset(['dtypes', 'corrwith'])
|
99 | 99 |
|
100 |
| -_cython_transforms = frozenset(['cumprod', 'cumsum', 'shift']) |
| 100 | +_cython_transforms = frozenset(['cumprod', 'cumsum', 'shift', |
| 101 | + 'cummin', 'cummax']) |
101 | 102 |
|
102 | 103 |
|
103 | 104 | def _groupby_function(name, alias, npfunc, numeric_only=True,
|
@@ -1415,6 +1416,24 @@ def cumsum(self, axis=0, *args, **kwargs):
|
1415 | 1416 |
|
1416 | 1417 | return self._cython_transform('cumsum')
|
1417 | 1418 |
|
| 1419 | + @Substitution(name='groupby') |
| 1420 | + @Appender(_doc_template) |
| 1421 | + def cummin(self, axis=0): |
| 1422 | + """Cumulative min for each group""" |
| 1423 | + if axis != 0: |
| 1424 | + return self.apply(lambda x: np.minimum.accumulate(x, axis)) |
| 1425 | + |
| 1426 | + return self._cython_transform('cummin') |
| 1427 | + |
| 1428 | + @Substitution(name='groupby') |
| 1429 | + @Appender(_doc_template) |
| 1430 | + def cummax(self, axis=0): |
| 1431 | + """Cumulative max for each group""" |
| 1432 | + if axis != 0: |
| 1433 | + return self.apply(lambda x: np.maximum.accumulate(x, axis)) |
| 1434 | + |
| 1435 | + return self._cython_transform('cummax') |
| 1436 | + |
1418 | 1437 | @Substitution(name='groupby')
|
1419 | 1438 | @Appender(_doc_template)
|
1420 | 1439 | def shift(self, periods=1, freq=None, axis=0):
|
@@ -1752,6 +1771,8 @@ def get_group_levels(self):
|
1752 | 1771 | 'transform': {
|
1753 | 1772 | 'cumprod': 'group_cumprod',
|
1754 | 1773 | 'cumsum': 'group_cumsum',
|
| 1774 | + 'cummin': 'group_cummin', |
| 1775 | + 'cummax': 'group_cummax', |
1755 | 1776 | }
|
1756 | 1777 | }
|
1757 | 1778 |
|
|
0 commit comments