Repository: pandas-dev/pandas

Issue:
BUG: cython version of groupby.cummax throws error on datetimes
#### Code Sample, a copy-pastable example if possible

```python
>>> import pandas as pd
>>> x = pd.DataFrame(dict(a=[1], b=pd.to_datetime(['2001'])))
>>> x.groupby('a').b.cummax()

Traceback (most recent call last):
  File "<ipython-input-9-316257648d5f>", line 1, in <module>
    x.groupby('a').b.cummax()
  File "~/anaconda3/lib/python3.5/site-packages/pandas/core/groupby.py", line 1454, in cummax
    return self._cython_transform('cummax', **kwargs)
  File "~/anaconda3/lib/python3.5/site-packages/pandas/core/groupby.py", line 806, in _cython_transform
    raise DataError('No numeric types to aggregate')
DataError: No numeric types to aggregate

```
#### Problem description

The current github version of pandas has cython implementations of `groupby.cummin` and `groupby.cummax`, which throw an error if called on datetime columns. (See #15048, 0fe491d.)
#### Expected Output

```python
0   2001-01-01
Name: b, dtype: datetime64[ns]
```

#### Output of ``pd.show_versions()``

<details>

INSTALLED VERSIONS
------------------
commit: None
python: 3.5.2.final.0
python-bits: 64
OS: Linux
OS-release: 4.9.8-100.fc24.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: C
LANG: C
LOCALE: None.None

pandas: 0.19.0+531.g04e1168
pytest: 3.0.5
pip: 9.0.1
setuptools: 27.2.0
Cython: 0.25.2
numpy: 1.11.3
scipy: 0.18.1
xarray: 0.9.1
IPython: 4.2.0
sphinx: 1.5.1
patsy: 0.4.1
dateutil: 2.6.0
pytz: 2016.10
blosc: None
bottleneck: 1.2.0
tables: 3.3.0
numexpr: 2.6.2
feather: None
matplotlib: 2.0.0
openpyxl: 2.4.1
xlrd: 1.0.0
xlwt: 1.2.0
xlsxwriter: 0.9.6
lxml: 3.7.2
bs4: 4.5.3
html5lib: 0.999
sqlalchemy: 1.1.5
pymysql: None
psycopg2: None
jinja2: 2.9.4
s3fs: None
pandas_gbq: None
pandas_datareader: None
</details>



Discussion:
I think this may be as easy as adding a `numeric_only=False` to this function call.  (of course with tests)

https://github.com/pandas-dev/pandas/blob/04e116851337cd852b4255f8221d9be44829e0e1/pandas/core/groupby.py#L1454
This is correct and not a bug. datetimes are not numeric types. This has to be specifically enabled.
this was covered by #15054 

```
In [29]: x = pd.DataFrame(dict(a=[1], b=pd.to_datetime(['2001'])))
    ...: >>> x.groupby('a').b.cummax(numeric_only=False)
    ...: 
    ...: 
Out[29]: 
0   2001-01-01
Name: b, dtype: datetime64[ns]
```
@jreback - maybe the API is set, but isn't this inconsistent?

```python
In [23]: df = pd.DataFrame(dict(a=[1], b=pd.to_datetime(['2001'])))

In [24]: df['b'].max()
Out[24]: Timestamp('2001-01-01 00:00:00')

In [25]: df['b'].cummax()
Out[25]: 
0   2001-01-01
Name: b, dtype: datetime64[ns]

In [26]: df.groupby('a')['b'].max()
Out[26]: 
a
1   2001-01-01
Name: b, dtype: datetime64[ns]

In [27]: df.groupby('a')['b'].cummax()
Out[27]: 
DataError: No numeric types to aggregate
```

@chris-b1 hmm, ahh we are defaulting ``numeric_only=False`` for ``.max``

yes that should be done for ``cummax``/``cummin``.

Resolving patch:
diff --git a/pandas/core/groupby.py b/pandas/core/groupby.py
--- a/pandas/core/groupby.py
+++ b/pandas/core/groupby.py
@@ -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)
@@ -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)


Test patch:
diff --git a/pandas/tests/groupby/test_groupby.py b/pandas/tests/groupby/test_groupby.py
--- a/pandas/tests/groupby/test_groupby.py
+++ b/pandas/tests/groupby/test_groupby.py
@@ -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)
@@ -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)