Skip to content

Commit 5e5d70d

Browse files
committed
BUG: Groupby.cummin/max DataError on datetimes (pandas-dev#15561)
1 parent d652485 commit 5e5d70d

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

doc/source/whatsnew/v0.20.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ Performance Improvements
635635
- Increased performance of ``pd.factorize()`` by releasing the GIL with ``object`` dtype when inferred as strings (:issue:`14859`)
636636
- Improved performance of timeseries plotting with an irregular DatetimeIndex
637637
(or with ``compat_x=True``) (:issue:`15073`).
638-
- Improved performance of ``groupby().cummin()`` and ``groupby().cummax()`` (:issue:`15048`, :issue:`15109`)
638+
- Improved performance of ``groupby().cummin()`` and ``groupby().cummax()`` (:issue:`15048`, :issue:`15109`, :issue:`15561`)
639639
- Improved performance and reduced memory when indexing with a ``MultiIndex`` (:issue:`15245`)
640640
- When reading buffer object in ``read_sas()`` method without specified format, filepath string is inferred rather than buffer object. (:issue:`14947`)
641641
- Improved performance of `rank()` for categorical data (:issue:`15498`)

pandas/core/groupby.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1442,7 +1442,7 @@ def cummin(self, axis=0, **kwargs):
14421442
if axis != 0:
14431443
return self.apply(lambda x: np.minimum.accumulate(x, axis))
14441444

1445-
return self._cython_transform('cummin', **kwargs)
1445+
return self._cython_transform('cummin', numeric_only=False)
14461446

14471447
@Substitution(name='groupby')
14481448
@Appender(_doc_template)
@@ -1451,7 +1451,7 @@ def cummax(self, axis=0, **kwargs):
14511451
if axis != 0:
14521452
return self.apply(lambda x: np.maximum.accumulate(x, axis))
14531453

1454-
return self._cython_transform('cummax', **kwargs)
1454+
return self._cython_transform('cummax', numeric_only=False)
14551455

14561456
@Substitution(name='groupby')
14571457
@Appender(_doc_template)

pandas/tests/groupby/test_groupby.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -1954,7 +1954,8 @@ def test_arg_passthru(self):
19541954
for attr in ['cummin', 'cummax']:
19551955
f = getattr(df.groupby('group'), attr)
19561956
result = f()
1957-
tm.assert_index_equal(result.columns, expected_columns_numeric)
1957+
# GH 15561: numeric_only=False set by default like min/max
1958+
tm.assert_index_equal(result.columns, expected_columns)
19581959

19591960
result = f(numeric_only=False)
19601961
tm.assert_index_equal(result.columns, expected_columns)
@@ -4295,6 +4296,13 @@ def test_cummin_cummax(self):
42954296
result = base_df.groupby('A').B.apply(lambda x: x.cummax()).to_frame()
42964297
tm.assert_frame_equal(expected, result)
42974298

4299+
# GH 15561
4300+
df = pd.DataFrame(dict(a=[1], b=pd.to_datetime(['2001'])))
4301+
expected = pd.Series(pd.to_datetime('2001'), index=[0], name='b')
4302+
for method in ['cummax', 'cummin']:
4303+
result = getattr(df.groupby('a')['b'], method)()
4304+
tm.assert_series_equal(expected, result)
4305+
42984306

42994307
def _check_groupby(df, result, keys, field, f=lambda x: x.sum()):
43004308
tups = lmap(tuple, df[keys].values)

0 commit comments

Comments
 (0)