Repository: pandas-dev/pandas

Issue:
Series.cummin raises ValueError when datetime64 Series contains NaT
Ref: http://stackoverflow.com/q/27240365/190597

```
s = pd.Series(pd.date_range('2008-09-15', periods=10, freq='m'))
s.loc[10] = pd.NaT
s.cummin()

ValueError: Could not convert object to NumPy datetime
```
- validate for `cummax` & `timedelta64[ns]`



Discussion:

Resolving patch:
diff --git a/pandas/core/generic.py b/pandas/core/generic.py
--- a/pandas/core/generic.py
+++ b/pandas/core/generic.py
@@ -4112,13 +4112,17 @@ def func(self, axis=None, dtype=None, out=None, skipna=True,
                     axis = self._get_axis_number(axis)
 
                 y = _values_from_object(self).copy()
-                if not issubclass(y.dtype.type, (np.integer, np.bool_)):
+
+                if skipna and issubclass(y.dtype.type, 
+                                         (np.datetime64, np.timedelta64)):
+                    result = accum_func(y, axis)
+                    mask = isnull(self)
+                    np.putmask(result, mask, pd.tslib.iNaT)
+                elif skipna and not issubclass(y.dtype.type, (np.integer, np.bool_)):
                     mask = isnull(self)
-                    if skipna:
-                        np.putmask(y, mask, mask_a)
+                    np.putmask(y, mask, mask_a)
                     result = accum_func(y, axis)
-                    if skipna:
-                        np.putmask(result, mask, mask_b)
+                    np.putmask(result, mask, mask_b)
                 else:
                     result = accum_func(y, axis)
 


Test patch:
diff --git a/pandas/tests/test_series.py b/pandas/tests/test_series.py
--- a/pandas/tests/test_series.py
+++ b/pandas/tests/test_series.py
@@ -2309,6 +2309,62 @@ def test_cummax(self):
 
         self.assert_numpy_array_equal(result, expected)
 
+    def test_cummin_datetime64(self):
+        s = pd.Series(pd.to_datetime(
+            ['NaT', '2000-1-2', 'NaT', '2000-1-1', 'NaT', '2000-1-3']))
+
+        expected = pd.Series(pd.to_datetime(
+            ['NaT', '2000-1-2', 'NaT', '2000-1-1', 'NaT', '2000-1-1']))
+        result = s.cummin(skipna=True)
+        self.assert_series_equal(expected, result)
+
+        expected = pd.Series(pd.to_datetime(
+            ['NaT', '2000-1-2', '2000-1-2', '2000-1-1', '2000-1-1', '2000-1-1']))
+        result = s.cummin(skipna=False)
+        self.assert_series_equal(expected, result)
+
+    def test_cummax_datetime64(self):
+        s = pd.Series(pd.to_datetime(
+            ['NaT', '2000-1-2', 'NaT', '2000-1-1', 'NaT', '2000-1-3']))
+
+        expected = pd.Series(pd.to_datetime(
+            ['NaT', '2000-1-2', 'NaT', '2000-1-2', 'NaT', '2000-1-3']))
+        result = s.cummax(skipna=True)
+        self.assert_series_equal(expected, result)
+
+        expected = pd.Series(pd.to_datetime(
+            ['NaT', '2000-1-2', '2000-1-2', '2000-1-2', '2000-1-2', '2000-1-3']))
+        result = s.cummax(skipna=False)
+        self.assert_series_equal(expected, result)
+
+    def test_cummin_timedelta64(self):
+        s = pd.Series(pd.to_timedelta(
+            ['NaT', '2 min', 'NaT', '1 min', 'NaT', '3 min', ]))
+
+        expected = pd.Series(pd.to_timedelta(
+            ['NaT', '2 min', 'NaT', '1 min', 'NaT', '1 min', ]))
+        result = s.cummin(skipna=True)
+        self.assert_series_equal(expected, result)
+
+        expected = pd.Series(pd.to_timedelta(
+            ['NaT', '2 min', '2 min', '1 min', '1 min', '1 min', ]))
+        result = s.cummin(skipna=False)
+        self.assert_series_equal(expected, result)
+
+    def test_cummax_timedelta64(self):
+        s = pd.Series(pd.to_timedelta(
+            ['NaT', '2 min', 'NaT', '1 min', 'NaT', '3 min', ]))
+
+        expected = pd.Series(pd.to_timedelta(
+            ['NaT', '2 min', 'NaT', '2 min', 'NaT', '3 min', ]))
+        result = s.cummax(skipna=True)
+        self.assert_series_equal(expected, result)
+
+        expected = pd.Series(pd.to_timedelta(
+            ['NaT', '2 min', '2 min', '2 min', '2 min', '3 min', ]))
+        result = s.cummax(skipna=False)
+        self.assert_series_equal(expected, result)
+
     def test_npdiff(self):
         raise nose.SkipTest("skipping due to Series no longer being an "
                             "ndarray")