diff --git a/pandas/core/common.py b/pandas/core/common.py index 00fa970c0f77a..884a841f6da7c 100644 --- a/pandas/core/common.py +++ b/pandas/core/common.py @@ -813,7 +813,8 @@ def diff(arr, n, axis=0): na_indexer[axis] = slice(None, n) if n >= 0 else slice(n, None) out_arr[tuple(na_indexer)] = na - if arr.ndim == 2 and arr.dtype.name in _diff_special: + if (arr.ndim == 2 and arr.dtype.name in _diff_special + and dtype != 'timedelta64[ns]'): f = _diff_special[arr.dtype.name] f(arr, out_arr, n, axis) else: diff --git a/pandas/tests/test_frame.py b/pandas/tests/test_frame.py index 4e5b00a6db765..f67d7bfb811d9 100644 --- a/pandas/tests/test_frame.py +++ b/pandas/tests/test_frame.py @@ -9285,6 +9285,16 @@ def test_diff_float_n(self): xp = self.tsframe.diff(1) assert_frame_equal(rs, xp) + def test_diff_timedelta(self): + df = DataFrame(dict(time=[Timestamp('20130101 9:01'), + Timestamp('20130101 9:02')], + value=[1.0,2.0])) + res = df.diff() + exp = DataFrame([[pd.NaT, np.nan], + [np.timedelta64(int(6e10), 'ns'), 1]], + columns=['time', 'value']) + assert_frame_equal(res, exp) + def test_pct_change(self): rs = self.tsframe.pct_change(fill_method=None) assert_frame_equal(rs, self.tsframe / self.tsframe.shift(1) - 1)