From 3d296eeebad931fe9e5087a561176ac75224502c Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Fri, 3 Jan 2020 11:20:28 -0800 Subject: [PATCH 1/2] REF: change TDI.delete behavior to match DTI.delete --- pandas/core/indexes/timedeltas.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/indexes/timedeltas.py b/pandas/core/indexes/timedeltas.py index 894b430f1c4fd..c387ca0971c12 100644 --- a/pandas/core/indexes/timedeltas.py +++ b/pandas/core/indexes/timedeltas.py @@ -494,7 +494,7 @@ def delete(self, loc): """ new_tds = np.delete(self.asi8, loc) - freq = "infer" + freq = None if is_integer(loc): if loc in (0, -len(self), -1, len(self) - 1): freq = self.freq @@ -505,7 +505,7 @@ def delete(self, loc): if loc.start in (0, None) or loc.stop in (len(self), None): freq = self.freq - return TimedeltaIndex(new_tds, name=self.name, freq=freq) + return self._shallow_copy(new_tds, freq=freq) TimedeltaIndex._add_comparison_ops() From b802be6fb0a1dcfe30aeb01a838a12cd99d3fd97 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Sat, 4 Jan 2020 10:06:03 -0800 Subject: [PATCH 2/2] add test --- pandas/tests/indexes/timedeltas/test_timedelta.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pandas/tests/indexes/timedeltas/test_timedelta.py b/pandas/tests/indexes/timedeltas/test_timedelta.py index 7703fbbbcad2a..3b52b93fa6369 100644 --- a/pandas/tests/indexes/timedeltas/test_timedelta.py +++ b/pandas/tests/indexes/timedeltas/test_timedelta.py @@ -201,6 +201,13 @@ def test_append_numpy_bug_1681(self): result = a.append(c) assert (result["B"] == td).all() + def test_delete_doesnt_infer_freq(self): + # GH#30655 behavior matches DatetimeIndex + + tdi = pd.TimedeltaIndex(["1 Day", "2 Days", None, "3 Days", "4 Days"]) + result = tdi.delete(2) + assert result.freq is None + def test_fields(self): rng = timedelta_range("1 days, 10:11:12.100123456", periods=2, freq="s") tm.assert_index_equal(rng.days, Index([1, 1], dtype="int64"))