Skip to content

Commit

Permalink
BUG: Groupby.cummin/max DataError on datetimes (#15561) (#15569)
Browse files Browse the repository at this point in the history
  • Loading branch information
mroeschke authored and TomAugspurger committed Mar 5, 2017
1 parent c198e28 commit f5b7bcb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.20.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ Performance Improvements
- Increased performance of ``pd.factorize()`` by releasing the GIL with ``object`` dtype when inferred as strings (:issue:`14859`)
- Improved performance of timeseries plotting with an irregular DatetimeIndex
(or with ``compat_x=True``) (:issue:`15073`).
- Improved performance of ``groupby().cummin()`` and ``groupby().cummax()`` (:issue:`15048`, :issue:`15109`)
- Improved performance of ``groupby().cummin()`` and ``groupby().cummax()`` (:issue:`15048`, :issue:`15109`, :issue:`15561`)
- Improved performance and reduced memory when indexing with a ``MultiIndex`` (:issue:`15245`)
- When reading buffer object in ``read_sas()`` method without specified format, filepath string is inferred rather than buffer object. (:issue:`14947`)
- Improved performance of `rank()` for categorical data (:issue:`15498`)
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -1442,7 +1442,7 @@ def cummin(self, axis=0, **kwargs):
if axis != 0:
return self.apply(lambda x: np.minimum.accumulate(x, axis))

return self._cython_transform('cummin', **kwargs)
return self._cython_transform('cummin', numeric_only=False)

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

return self._cython_transform('cummax', **kwargs)
return self._cython_transform('cummax', numeric_only=False)

@Substitution(name='groupby')
@Appender(_doc_template)
Expand Down
10 changes: 9 additions & 1 deletion pandas/tests/groupby/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -1954,7 +1954,8 @@ def test_arg_passthru(self):
for attr in ['cummin', 'cummax']:
f = getattr(df.groupby('group'), attr)
result = f()
tm.assert_index_equal(result.columns, expected_columns_numeric)
# GH 15561: numeric_only=False set by default like min/max
tm.assert_index_equal(result.columns, expected_columns)

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

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


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

0 comments on commit f5b7bcb

Please sign in to comment.