Skip to content

Commit 5ace1fd

Browse files
ivanovmgJulianWgs
authored andcommitted
BUG: record warnings related to DatetimeIndex (pandas-dev#37193)
1 parent 3273fad commit 5ace1fd

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

pandas/tests/plotting/test_datetimelike.py

+20-6
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,16 @@ def test_irreg_hf(self):
291291
_, ax = self.plt.subplots()
292292
df2 = df.copy()
293293
df2.index = df.index.astype(object)
294-
df2.plot(ax=ax)
295-
diffs = Series(ax.get_lines()[0].get_xydata()[:, 0]).diff()
296-
assert (np.fabs(diffs[1:] - sec) < 1e-8).all()
294+
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
295+
# This warning will be emitted
296+
# pandas/core/frame.py:3216:
297+
# FutureWarning: Automatically casting object-dtype Index of datetimes
298+
# to DatetimeIndex is deprecated and will be removed in a future version.
299+
# Explicitly cast to DatetimeIndex instead.
300+
# return klass(values, index=self.index, name=name, fastpath=True)
301+
df2.plot(ax=ax)
302+
diffs = Series(ax.get_lines()[0].get_xydata()[:, 0]).diff()
303+
assert (np.fabs(diffs[1:] - sec) < 1e-8).all()
297304

298305
def test_irregular_datetime64_repr_bug(self):
299306
ser = tm.makeTimeSeries()
@@ -1028,9 +1035,16 @@ def test_irreg_dtypes(self):
10281035
# np.datetime64
10291036
idx = date_range("1/1/2000", periods=10)
10301037
idx = idx[[0, 2, 5, 9]].astype(object)
1031-
df = DataFrame(np.random.randn(len(idx), 3), idx)
1032-
_, ax = self.plt.subplots()
1033-
_check_plot_works(df.plot, ax=ax)
1038+
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
1039+
# This warning will be emitted
1040+
# pandas/core/frame.py:3216:
1041+
# FutureWarning: Automatically casting object-dtype Index of datetimes
1042+
# to DatetimeIndex is deprecated and will be removed in a future version.
1043+
# Explicitly cast to DatetimeIndex instead.
1044+
# return klass(values, index=self.index, name=name, fastpath=True)
1045+
df = DataFrame(np.random.randn(len(idx), 3), idx)
1046+
_, ax = self.plt.subplots()
1047+
_check_plot_works(df.plot, ax=ax)
10341048

10351049
@pytest.mark.slow
10361050
def test_time(self):

0 commit comments

Comments
 (0)