diff --git a/pandas/_testing.py b/pandas/_testing.py index 21e74dafcc944..7ca14546fd46b 100644 --- a/pandas/_testing.py +++ b/pandas/_testing.py @@ -1429,6 +1429,8 @@ def assert_equal(left, right, **kwargs): if isinstance(left, pd.Index): assert_index_equal(left, right, **kwargs) + if isinstance(left, (pd.DatetimeIndex, pd.TimedeltaIndex)): + assert left.freq == right.freq, (left.freq, right.freq) elif isinstance(left, pd.Series): assert_series_equal(left, right, **kwargs) elif isinstance(left, pd.DataFrame): diff --git a/pandas/tests/arithmetic/test_datetime64.py b/pandas/tests/arithmetic/test_datetime64.py index afdfece842ef9..83d81ccf84b45 100644 --- a/pandas/tests/arithmetic/test_datetime64.py +++ b/pandas/tests/arithmetic/test_datetime64.py @@ -897,7 +897,7 @@ def test_dt64arr_add_sub_td64ndarray(self, tz_naive_fixture, box_with_array): ) def test_dt64arr_sub_dtscalar(self, box_with_array, ts): # GH#8554, GH#22163 DataFrame op should _not_ return dt64 dtype - idx = pd.date_range("2013-01-01", periods=3) + idx = pd.date_range("2013-01-01", periods=3)._with_freq(None) idx = tm.box_expected(idx, box_with_array) expected = pd.TimedeltaIndex(["0 Days", "1 Day", "2 Days"]) @@ -912,7 +912,7 @@ def test_dt64arr_sub_datetime64_not_ns(self, box_with_array): dt64 = np.datetime64("2013-01-01") assert dt64.dtype == "datetime64[D]" - dti = pd.date_range("20130101", periods=3) + dti = pd.date_range("20130101", periods=3)._with_freq(None) dtarr = tm.box_expected(dti, box_with_array) expected = pd.TimedeltaIndex(["0 Days", "1 Day", "2 Days"]) @@ -926,6 +926,7 @@ def test_dt64arr_sub_datetime64_not_ns(self, box_with_array): def test_dt64arr_sub_timestamp(self, box_with_array): ser = pd.date_range("2014-03-17", periods=2, freq="D", tz="US/Eastern") + ser = ser._with_freq(None) ts = ser[0] ser = tm.box_expected(ser, box_with_array)