diff --git a/pandas/_testing.py b/pandas/_testing.py index 18b5677e7864d..eb4eb86c78b2d 100644 --- a/pandas/_testing.py +++ b/pandas/_testing.py @@ -1171,6 +1171,10 @@ def assert_series_equal( check_categorical=check_categorical, obj=f"{obj}.index", ) + if isinstance(left.index, (pd.DatetimeIndex, pd.TimedeltaIndex)): + lidx = left.index + ridx = right.index + assert lidx.freq == ridx.freq, (lidx.freq, ridx.freq) if check_dtype: # We want to skip exact dtype checking when `check_categorical` diff --git a/pandas/tests/arithmetic/test_numeric.py b/pandas/tests/arithmetic/test_numeric.py index 0675ba874846b..b085ee968dadb 100644 --- a/pandas/tests/arithmetic/test_numeric.py +++ b/pandas/tests/arithmetic/test_numeric.py @@ -919,6 +919,8 @@ def _check_op(series, other, op, pos_only=False): cython_or_numpy = op(left, right) python = left.combine(right, op) + if isinstance(other, Series) and not other.index.equals(series.index): + python.index = python.index._with_freq(None) tm.assert_series_equal(cython_or_numpy, python) def check(series, other): diff --git a/pandas/tests/frame/methods/test_at_time.py b/pandas/tests/frame/methods/test_at_time.py index 108bbbfa183c4..71368f270147f 100644 --- a/pandas/tests/frame/methods/test_at_time.py +++ b/pandas/tests/frame/methods/test_at_time.py @@ -83,4 +83,8 @@ def test_at_time_axis(self, axis): expected = ts.loc[:, indices] result = ts.at_time("9:30", axis=axis) + + # Without clearing freq, result has freq 1440T and expected 5T + result.index = result.index._with_freq(None) + expected.index = expected.index._with_freq(None) tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/frame/methods/test_shift.py b/pandas/tests/frame/methods/test_shift.py index f6c89172bbf86..95f9fd9d7caf3 100644 --- a/pandas/tests/frame/methods/test_shift.py +++ b/pandas/tests/frame/methods/test_shift.py @@ -177,8 +177,12 @@ def test_tshift(self, datetime_frame): columns=datetime_frame.columns, ) shifted = inferred_ts.tshift(1) + + expected = datetime_frame.tshift(1) + expected.index = expected.index._with_freq(None) + tm.assert_frame_equal(shifted, expected) + unshifted = shifted.tshift(-1) - tm.assert_frame_equal(shifted, datetime_frame.tshift(1)) tm.assert_frame_equal(unshifted, inferred_ts) no_freq = datetime_frame.iloc[[0, 5, 7], :] diff --git a/pandas/tests/groupby/test_timegrouper.py b/pandas/tests/groupby/test_timegrouper.py index 6d29ebd7ba795..06a83f4c000cf 100644 --- a/pandas/tests/groupby/test_timegrouper.py +++ b/pandas/tests/groupby/test_timegrouper.py @@ -747,6 +747,7 @@ def test_nunique_with_timegrouper_and_nat(self): grouper = pd.Grouper(key="time", freq="h") result = test.groupby(grouper)["data"].nunique() expected = test[test.time.notnull()].groupby(grouper)["data"].nunique() + expected.index = expected.index._with_freq(None) tm.assert_series_equal(result, expected) def test_scalar_call_versus_list_call(self): diff --git a/pandas/tests/indexes/timedeltas/test_ops.py b/pandas/tests/indexes/timedeltas/test_ops.py index 19cbd74b31172..3e452e7e2841d 100644 --- a/pandas/tests/indexes/timedeltas/test_ops.py +++ b/pandas/tests/indexes/timedeltas/test_ops.py @@ -18,10 +18,14 @@ def test_value_counts_unique(self): idx = TimedeltaIndex(np.repeat(idx.values, range(1, len(idx) + 1))) exp_idx = timedelta_range("1 days 18:00:00", freq="-1H", periods=10) + exp_idx = exp_idx._with_freq(None) expected = Series(range(10, 0, -1), index=exp_idx, dtype="int64") - for obj in [idx, Series(idx)]: - tm.assert_series_equal(obj.value_counts(), expected) + obj = idx + tm.assert_series_equal(obj.value_counts(), expected) + + obj = Series(idx) + tm.assert_series_equal(obj.value_counts(), expected) expected = timedelta_range("1 days 09:00:00", freq="H", periods=10) tm.assert_index_equal(idx.unique(), expected) diff --git a/pandas/tests/indexing/test_datetime.py b/pandas/tests/indexing/test_datetime.py index 17ca23055f6e0..ad71b6b72df33 100644 --- a/pandas/tests/indexing/test_datetime.py +++ b/pandas/tests/indexing/test_datetime.py @@ -146,7 +146,7 @@ def test_indexing_with_datetimeindex_tz(self): for sel in (index, list(index)): # getitem result = ser[sel] - expected = ser + expected = ser.copy() if sel is not index: expected.index = expected.index._with_freq(None) tm.assert_series_equal(result, expected) @@ -159,7 +159,10 @@ def test_indexing_with_datetimeindex_tz(self): # .loc getitem result = ser.loc[sel] - tm.assert_series_equal(result, ser) + expected = ser.copy() + if sel is not index: + expected.index = expected.index._with_freq(None) + tm.assert_series_equal(result, expected) # .loc setitem result = ser.copy() diff --git a/pandas/tests/resample/test_datetime_index.py b/pandas/tests/resample/test_datetime_index.py index f15d39e9e6456..3b4cbbd0086ef 100644 --- a/pandas/tests/resample/test_datetime_index.py +++ b/pandas/tests/resample/test_datetime_index.py @@ -6,6 +6,7 @@ import pytest import pytz +from pandas._libs import lib from pandas.errors import UnsupportedFunctionCall import pandas as pd @@ -62,6 +63,7 @@ def test_custom_grouper(index): arr = [1] + [5] * 2592 idx = dti[0:-1:5] idx = idx.append(dti[-1:]) + idx = pd.DatetimeIndex(idx, freq="5T") expect = Series(arr, index=idx) # GH2763 - return in put dtype if we can @@ -502,15 +504,18 @@ def test_resample_how_method(): ) expected = Series( [11, np.NaN, np.NaN, np.NaN, np.NaN, np.NaN, 22], - index=[ - Timestamp("2015-03-31 21:48:50"), - Timestamp("2015-03-31 21:49:00"), - Timestamp("2015-03-31 21:49:10"), - Timestamp("2015-03-31 21:49:20"), - Timestamp("2015-03-31 21:49:30"), - Timestamp("2015-03-31 21:49:40"), - Timestamp("2015-03-31 21:49:50"), - ], + index=pd.DatetimeIndex( + [ + Timestamp("2015-03-31 21:48:50"), + Timestamp("2015-03-31 21:49:00"), + Timestamp("2015-03-31 21:49:10"), + Timestamp("2015-03-31 21:49:20"), + Timestamp("2015-03-31 21:49:30"), + Timestamp("2015-03-31 21:49:40"), + Timestamp("2015-03-31 21:49:50"), + ], + freq="10s", + ), ) tm.assert_series_equal(s.resample("10S").mean(), expected) @@ -778,7 +783,7 @@ def test_resample_single_group(): [30.1, 31.6], index=[Timestamp("20070915 15:30:00"), Timestamp("20070915 15:40:00")], ) - expected = Series([0.75], index=[Timestamp("20070915")]) + expected = Series([0.75], index=pd.DatetimeIndex([Timestamp("20070915")], freq="D")) result = s.resample("D").apply(lambda x: np.std(x)) tm.assert_series_equal(result, expected) @@ -801,7 +806,9 @@ def test_resample_float_base(): base = 17 + 43.51 / 60 result = s.resample("3min", base=base).size() - expected = Series(3, index=pd.DatetimeIndex(["2018-11-26 16:17:43.51"])) + expected = Series( + 3, index=pd.DatetimeIndex(["2018-11-26 16:17:43.51"], freq="3min") + ) tm.assert_series_equal(result, expected) @@ -938,6 +945,8 @@ def test_resample_anchored_intraday(simple_date_range_series): result = df.resample("M").mean() expected = df.resample("M", kind="period").mean().to_timestamp(how="end") expected.index += Timedelta(1, "ns") - Timedelta(1, "D") + expected.index = expected.index._with_freq("infer") + assert expected.index.freq == "M" tm.assert_frame_equal(result, expected) result = df.resample("M", closed="left").mean() @@ -945,6 +954,8 @@ def test_resample_anchored_intraday(simple_date_range_series): exp = exp.to_timestamp(how="end") exp.index = exp.index + Timedelta(1, "ns") - Timedelta(1, "D") + exp.index = exp.index._with_freq("infer") + assert exp.index.freq == "M" tm.assert_frame_equal(result, exp) rng = date_range("1/1/2012", "4/1/2012", freq="100min") @@ -953,12 +964,16 @@ def test_resample_anchored_intraday(simple_date_range_series): result = df.resample("Q").mean() expected = df.resample("Q", kind="period").mean().to_timestamp(how="end") expected.index += Timedelta(1, "ns") - Timedelta(1, "D") + expected.index._data.freq = "Q" + expected.index._freq = lib.no_default tm.assert_frame_equal(result, expected) result = df.resample("Q", closed="left").mean() expected = df.tshift(1, freq="D").resample("Q", kind="period", closed="left").mean() expected = expected.to_timestamp(how="end") expected.index += Timedelta(1, "ns") - Timedelta(1, "D") + expected.index._data.freq = "Q" + expected.index._freq = lib.no_default tm.assert_frame_equal(result, expected) ts = simple_date_range_series("2012-04-29 23:00", "2012-04-30 5:00", freq="h") @@ -1151,6 +1166,8 @@ def test_resample_timegrouper(): name="A", ) expected = DataFrame({"B": [1, 0, 2, 2, 1]}, index=exp_idx) + if df["A"].isna().any(): + expected.index = expected.index._with_freq(None) tm.assert_frame_equal(result, expected) result = df.groupby(pd.Grouper(freq="M", key="A")).count() @@ -1163,6 +1180,8 @@ def test_resample_timegrouper(): index=exp_idx, columns=["B", "C"], ) + if df["A"].isna().any(): + expected.index = expected.index._with_freq(None) tm.assert_frame_equal(result, expected) result = df.groupby(pd.Grouper(freq="M", key="A")).count() @@ -1291,7 +1310,8 @@ def test_resample_across_dst(): dti2 = DatetimeIndex( pd.to_datetime(df2.ts, unit="s") .dt.tz_localize("UTC") - .dt.tz_convert("Europe/Madrid") + .dt.tz_convert("Europe/Madrid"), + freq="H", ) df = DataFrame([5, 5], index=dti1) @@ -1322,13 +1342,17 @@ def test_resample_dst_anchor(): # 5172 dti = DatetimeIndex([datetime(2012, 11, 4, 23)], tz="US/Eastern") df = DataFrame([5], index=dti) - tm.assert_frame_equal( - df.resample(rule="D").sum(), DataFrame([5], index=df.index.normalize()) - ) + + dti = DatetimeIndex(df.index.normalize(), freq="D") + expected = DataFrame([5], index=dti) + tm.assert_frame_equal(df.resample(rule="D").sum(), expected) df.resample(rule="MS").sum() tm.assert_frame_equal( df.resample(rule="MS").sum(), - DataFrame([5], index=DatetimeIndex([datetime(2012, 11, 1)], tz="US/Eastern")), + DataFrame( + [5], + index=DatetimeIndex([datetime(2012, 11, 1)], tz="US/Eastern", freq="MS"), + ), ) dti = date_range("2013-09-30", "2013-11-02", freq="30Min", tz="Europe/Paris") @@ -1424,7 +1448,9 @@ def test_downsample_across_dst_weekly(): result = df.resample("1W").sum() expected = DataFrame( [23, 42], - index=pd.DatetimeIndex(["2017-03-26", "2017-04-02"], tz="Europe/Amsterdam"), + index=pd.DatetimeIndex( + ["2017-03-26", "2017-04-02"], tz="Europe/Amsterdam", freq="W" + ), ) tm.assert_frame_equal(result, expected) @@ -1447,12 +1473,12 @@ def test_downsample_dst_at_midnight(): data = list(range(len(index))) dataframe = pd.DataFrame(data, index=index) result = dataframe.groupby(pd.Grouper(freq="1D")).mean() - expected = DataFrame( - [7.5, 28.0, 44.5], - index=date_range("2018-11-03", periods=3).tz_localize( - "America/Havana", ambiguous=True - ), + + dti = date_range("2018-11-03", periods=3).tz_localize( + "America/Havana", ambiguous=True ) + dti = pd.DatetimeIndex(dti, freq="D") + expected = DataFrame([7.5, 28.0, 44.5], index=dti,) tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/resample/test_period_index.py b/pandas/tests/resample/test_period_index.py index 70b65209db955..ebc75018bb52d 100644 --- a/pandas/tests/resample/test_period_index.py +++ b/pandas/tests/resample/test_period_index.py @@ -270,7 +270,10 @@ def test_resample_with_pytz(self): ) result = s.resample("D").mean() expected = Series( - 2, index=pd.DatetimeIndex(["2017-01-01", "2017-01-02"], tz="US/Eastern") + 2, + index=pd.DatetimeIndex( + ["2017-01-01", "2017-01-02"], tz="US/Eastern", freq="D" + ), ) tm.assert_series_equal(result, expected) # Especially assert that the timezone is LMT for pytz @@ -308,6 +311,7 @@ def test_resample_nonexistent_time_bin_edge(self): index = date_range("2017-03-12", "2017-03-12 1:45:00", freq="15T") s = Series(np.zeros(len(index)), index=index) expected = s.tz_localize("US/Pacific") + expected.index = pd.DatetimeIndex(expected.index, freq="900S") result = expected.resample("900S").mean() tm.assert_series_equal(result, expected) @@ -471,6 +475,7 @@ def test_resample_tz_localized(self): ] exp = ts_local_naive.resample("W").mean().tz_localize("America/Los_Angeles") + exp.index = pd.DatetimeIndex(exp.index, freq="W") tm.assert_series_equal(result, exp) @@ -582,6 +587,7 @@ def test_resample_with_dst_time_change(self): index = pd.to_datetime(expected_index_values, utc=True).tz_convert( "America/Chicago" ) + index = pd.DatetimeIndex(index, freq="12h") expected = pd.DataFrame( [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0], index=index, @@ -650,7 +656,9 @@ def test_evenly_divisible_with_no_extra_bins(self): df = DataFrame(np.random.randn(9, 3), index=date_range("2000-1-1", periods=9)) result = df.resample("5D").mean() expected = pd.concat([df.iloc[0:5].mean(), df.iloc[5:].mean()], axis=1).T - expected.index = [Timestamp("2000-1-1"), Timestamp("2000-1-6")] + expected.index = pd.DatetimeIndex( + [Timestamp("2000-1-1"), Timestamp("2000-1-6")], freq="5D" + ) tm.assert_frame_equal(result, expected) index = date_range(start="2001-5-4", periods=28) @@ -836,6 +844,9 @@ def test_resample_with_non_zero_base(self, start, end, start_freq, end_freq, bas # to_timestamp casts 24H -> D result = result.asfreq(end_freq) if end_freq == "24H" else result expected = s.to_timestamp().resample(end_freq, base=base).mean() + if end_freq == "M": + # TODO: is non-tick the relevant characteristic? + expected.index = expected.index._with_freq(None) tm.assert_series_equal(result, expected) @pytest.mark.parametrize( diff --git a/pandas/tests/resample/test_time_grouper.py b/pandas/tests/resample/test_time_grouper.py index bf998a6e83909..49ac5f81f9c02 100644 --- a/pandas/tests/resample/test_time_grouper.py +++ b/pandas/tests/resample/test_time_grouper.py @@ -170,7 +170,7 @@ def test_resample_entirly_nat_window(method, method_args, unit): s = pd.Series([0] * 2 + [np.nan] * 2, index=pd.date_range("2017", periods=4)) result = methodcaller(method, **method_args)(s.resample("2d")) expected = pd.Series( - [0.0, unit], index=pd.to_datetime(["2017-01-01", "2017-01-03"]) + [0.0, unit], index=pd.DatetimeIndex(["2017-01-01", "2017-01-03"], freq="2D") ) tm.assert_series_equal(result, expected) @@ -207,7 +207,8 @@ def test_aggregate_with_nat(func, fill_value): pad = DataFrame([[fill_value] * 4], index=[3], columns=["A", "B", "C", "D"]) expected = normal_result.append(pad) expected = expected.sort_index() - expected.index = date_range(start="2013-01-01", freq="D", periods=5, name="key") + dti = date_range(start="2013-01-01", freq="D", periods=5, name="key") + expected.index = dti._with_freq(None) # TODO: is this desired? tm.assert_frame_equal(expected, dt_result) assert dt_result.index.name == "key" @@ -237,7 +238,9 @@ def test_aggregate_with_nat_size(): pad = Series([0], index=[3]) expected = normal_result.append(pad) expected = expected.sort_index() - expected.index = date_range(start="2013-01-01", freq="D", periods=5, name="key") + expected.index = date_range( + start="2013-01-01", freq="D", periods=5, name="key" + )._with_freq(None) tm.assert_series_equal(expected, dt_result) assert dt_result.index.name == "key" @@ -269,8 +272,9 @@ def test_repr(): def test_upsample_sum(method, method_args, expected_values): s = pd.Series(1, index=pd.date_range("2017", periods=2, freq="H")) resampled = s.resample("30T") - index = pd.to_datetime( - ["2017-01-01T00:00:00", "2017-01-01T00:30:00", "2017-01-01T01:00:00"] + index = pd.DatetimeIndex( + ["2017-01-01T00:00:00", "2017-01-01T00:30:00", "2017-01-01T01:00:00"], + freq="30T", ) result = methodcaller(method, **method_args)(resampled) expected = pd.Series(expected_values, index=index) diff --git a/pandas/tests/resample/test_timedelta.py b/pandas/tests/resample/test_timedelta.py index a4d14f127b80e..9fc355a45b656 100644 --- a/pandas/tests/resample/test_timedelta.py +++ b/pandas/tests/resample/test_timedelta.py @@ -102,7 +102,7 @@ def test_resample_categorical_data_with_timedeltaindex(): result = df.resample("10s").agg(lambda x: (x.value_counts().index[0])) expected = DataFrame( {"Group_obj": ["A", "A"], "Group": ["A", "A"]}, - index=pd.to_timedelta([0, 10], unit="s"), + index=pd.TimedeltaIndex([0, 10], unit="s", freq="10s"), ) expected = expected.reindex(["Group_obj", "Group"], axis=1) expected["Group"] = expected["Group_obj"] diff --git a/pandas/tests/reshape/test_pivot.py b/pandas/tests/reshape/test_pivot.py index e49b80e476003..c07a5673fe503 100644 --- a/pandas/tests/reshape/test_pivot.py +++ b/pandas/tests/reshape/test_pivot.py @@ -423,7 +423,7 @@ def test_pivot_no_values(self): index=pd.Grouper(freq="A"), columns=pd.Grouper(key="dt", freq="M") ) exp = pd.DataFrame( - [3], index=pd.DatetimeIndex(["2011-12-31"]), columns=exp_columns + [3], index=pd.DatetimeIndex(["2011-12-31"], freq="A"), columns=exp_columns ) tm.assert_frame_equal(res, exp) @@ -1224,7 +1224,7 @@ def test_pivot_timegrouper(self): expected = DataFrame( np.array([10, 18, 3], dtype="int64").reshape(1, 3), - index=[datetime(2013, 12, 31)], + index=pd.DatetimeIndex([datetime(2013, 12, 31)], freq="A"), columns="Carl Joe Mark".split(), ) expected.index.name = "Date" @@ -1250,7 +1250,9 @@ def test_pivot_timegrouper(self): expected = DataFrame( np.array([1, np.nan, 3, 9, 18, np.nan]).reshape(2, 3), - index=[datetime(2013, 1, 1), datetime(2013, 7, 1)], + index=pd.DatetimeIndex( + [datetime(2013, 1, 1), datetime(2013, 7, 1)], freq="6MS" + ), columns="Carl Joe Mark".split(), ) expected.index.name = "Date" @@ -1407,18 +1409,24 @@ def test_pivot_timegrouper(self): np.nan, ] ).reshape(4, 4), - index=[ - datetime(2013, 9, 30), - datetime(2013, 10, 31), - datetime(2013, 11, 30), - datetime(2013, 12, 31), - ], - columns=[ - datetime(2013, 9, 30), - datetime(2013, 10, 31), - datetime(2013, 11, 30), - datetime(2013, 12, 31), - ], + index=pd.DatetimeIndex( + [ + datetime(2013, 9, 30), + datetime(2013, 10, 31), + datetime(2013, 11, 30), + datetime(2013, 12, 31), + ], + freq="M", + ), + columns=pd.DatetimeIndex( + [ + datetime(2013, 9, 30), + datetime(2013, 10, 31), + datetime(2013, 11, 30), + datetime(2013, 12, 31), + ], + freq="M", + ), ) expected.index.name = "Date" expected.columns.name = "PayDay" diff --git a/pandas/tests/series/indexing/test_datetime.py b/pandas/tests/series/indexing/test_datetime.py index e369631a5565d..22ef966299d5b 100644 --- a/pandas/tests/series/indexing/test_datetime.py +++ b/pandas/tests/series/indexing/test_datetime.py @@ -51,7 +51,7 @@ def test_fancy_setitem(): def test_dti_reset_index_round_trip(): - dti = date_range(start="1/1/2001", end="6/1/2001", freq="D") + dti = date_range(start="1/1/2001", end="6/1/2001", freq="D")._with_freq(None) d1 = DataFrame({"v": np.random.rand(len(dti))}, index=dti) d2 = d1.reset_index() assert d2.dtypes[0] == np.dtype("M8[ns]") @@ -568,6 +568,7 @@ def compare(slobj): result = ts2[slobj].copy() result = result.sort_index() expected = ts[slobj] + expected.index = expected.index._with_freq(None) tm.assert_series_equal(result, expected) compare(slice("2011-01-01", "2011-01-15")) @@ -582,6 +583,7 @@ def compare(slobj): # single values result = ts2["2011"].sort_index() expected = ts["2011"] + expected.index = expected.index._with_freq(None) tm.assert_series_equal(result, expected) # diff freq diff --git a/pandas/tests/series/methods/test_at_time.py b/pandas/tests/series/methods/test_at_time.py index d9985cf33776a..810e4c1446708 100644 --- a/pandas/tests/series/methods/test_at_time.py +++ b/pandas/tests/series/methods/test_at_time.py @@ -43,12 +43,17 @@ def test_at_time(self): expected = ts[(rng.hour == 9) & (rng.minute == 30)] exp_df = df[(rng.hour == 9) & (rng.minute == 30)] + result.index = result.index._with_freq(None) tm.assert_series_equal(result, expected) tm.assert_frame_equal(result_df, exp_df) chunk = df.loc["1/4/2000":] result = chunk.loc[time(9, 30)] expected = result_df[-1:] + + # Without resetting the freqs, these are 5 min and 1440 min, respectively + result.index = result.index._with_freq(None) + expected.index = expected.index._with_freq(None) tm.assert_frame_equal(result, expected) # midnight, everything diff --git a/pandas/tests/series/methods/test_shift.py b/pandas/tests/series/methods/test_shift.py index e8d7f5958d0a1..686e66162fe0b 100644 --- a/pandas/tests/series/methods/test_shift.py +++ b/pandas/tests/series/methods/test_shift.py @@ -212,8 +212,11 @@ def test_tshift(self, datetime_series): datetime_series.values, Index(np.asarray(datetime_series.index)), name="ts" ) shifted = inferred_ts.tshift(1) + expected = datetime_series.tshift(1) + expected.index = expected.index._with_freq(None) + tm.assert_series_equal(shifted, expected) + unshifted = shifted.tshift(-1) - tm.assert_series_equal(shifted, datetime_series.tshift(1)) tm.assert_series_equal(unshifted, inferred_ts) no_freq = datetime_series[[0, 5, 7]] diff --git a/pandas/tests/series/test_cumulative.py b/pandas/tests/series/test_cumulative.py index 0cb1c038478f5..259c5d53c5492 100644 --- a/pandas/tests/series/test_cumulative.py +++ b/pandas/tests/series/test_cumulative.py @@ -53,6 +53,7 @@ def test_cummin(self, datetime_series): result = ts.cummin()[1::2] expected = np.minimum.accumulate(ts.dropna()) + result.index = result.index._with_freq(None) tm.assert_series_equal(result, expected) @pytest.mark.xfail( @@ -70,6 +71,7 @@ def test_cummax(self, datetime_series): result = ts.cummax()[1::2] expected = np.maximum.accumulate(ts.dropna()) + result.index = result.index._with_freq(None) tm.assert_series_equal(result, expected) @pytest.mark.parametrize("tz", [None, "US/Pacific"]) diff --git a/pandas/tests/series/test_missing.py b/pandas/tests/series/test_missing.py index 9e9b93a499487..a64a6bc584cf6 100644 --- a/pandas/tests/series/test_missing.py +++ b/pandas/tests/series/test_missing.py @@ -744,6 +744,7 @@ def test_dropna_intervals(self): def test_valid(self, datetime_series): ts = datetime_series.copy() + ts.index = ts.index._with_freq(None) ts[::2] = np.NaN result = ts.dropna() diff --git a/pandas/tests/series/test_timeseries.py b/pandas/tests/series/test_timeseries.py index 3c3108835416a..15b6481c08a61 100644 --- a/pandas/tests/series/test_timeseries.py +++ b/pandas/tests/series/test_timeseries.py @@ -39,6 +39,7 @@ def test_promote_datetime_date(self): result = ts + ts2 result2 = ts2 + ts expected = ts + ts[5:] + expected.index = expected.index._with_freq(None) tm.assert_series_equal(result, expected) tm.assert_series_equal(result2, expected) diff --git a/pandas/tests/window/common.py b/pandas/tests/window/common.py index 6aeada3152dbb..a2450f4ac5203 100644 --- a/pandas/tests/window/common.py +++ b/pandas/tests/window/common.py @@ -352,6 +352,7 @@ def get_result(obj, obj2=None): result = result.loc[(slice(None), 1), 5] result.index = result.index.droplevel(1) expected = get_result(self.frame[1], self.frame[5]) + expected.index = expected.index._with_freq(None) tm.assert_series_equal(result, expected, check_names=False) diff --git a/pandas/tests/window/test_rolling.py b/pandas/tests/window/test_rolling.py index ab2c7fcb7a0dc..866b7da59382d 100644 --- a/pandas/tests/window/test_rolling.py +++ b/pandas/tests/window/test_rolling.py @@ -7,7 +7,7 @@ import pandas.util._test_decorators as td import pandas as pd -from pandas import DataFrame, Index, Series +from pandas import DataFrame, Series import pandas._testing as tm from pandas.core.window import Rolling from pandas.tests.window.common import Base @@ -436,7 +436,9 @@ def test_rolling_window_as_string(): + [95.0] * 20 ) - expected = Series(expData, index=Index(days, name="DateCol"), name="metric") + expected = Series( + expData, index=days.rename("DateCol")._with_freq(None), name="metric" + ) tm.assert_series_equal(result, expected)