diff --git a/pandas/tests/plotting/test_datetimelike.py b/pandas/tests/plotting/test_datetimelike.py index 78aa1887f5611..66463a4a2358a 100644 --- a/pandas/tests/plotting/test_datetimelike.py +++ b/pandas/tests/plotting/test_datetimelike.py @@ -291,9 +291,16 @@ def test_irreg_hf(self): _, ax = self.plt.subplots() df2 = df.copy() df2.index = df.index.astype(object) - df2.plot(ax=ax) - diffs = Series(ax.get_lines()[0].get_xydata()[:, 0]).diff() - assert (np.fabs(diffs[1:] - sec) < 1e-8).all() + with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + # This warning will be emitted + # pandas/core/frame.py:3216: + # FutureWarning: Automatically casting object-dtype Index of datetimes + # to DatetimeIndex is deprecated and will be removed in a future version. + # Explicitly cast to DatetimeIndex instead. + # return klass(values, index=self.index, name=name, fastpath=True) + df2.plot(ax=ax) + diffs = Series(ax.get_lines()[0].get_xydata()[:, 0]).diff() + assert (np.fabs(diffs[1:] - sec) < 1e-8).all() def test_irregular_datetime64_repr_bug(self): ser = tm.makeTimeSeries() @@ -1028,9 +1035,16 @@ def test_irreg_dtypes(self): # np.datetime64 idx = date_range("1/1/2000", periods=10) idx = idx[[0, 2, 5, 9]].astype(object) - df = DataFrame(np.random.randn(len(idx), 3), idx) - _, ax = self.plt.subplots() - _check_plot_works(df.plot, ax=ax) + with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + # This warning will be emitted + # pandas/core/frame.py:3216: + # FutureWarning: Automatically casting object-dtype Index of datetimes + # to DatetimeIndex is deprecated and will be removed in a future version. + # Explicitly cast to DatetimeIndex instead. + # return klass(values, index=self.index, name=name, fastpath=True) + df = DataFrame(np.random.randn(len(idx), 3), idx) + _, ax = self.plt.subplots() + _check_plot_works(df.plot, ax=ax) @pytest.mark.slow def test_time(self):