Skip to content

BUG: record warnings related to DatetimeIndex #37193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 23, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions pandas/tests/plotting/test_datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from datetime import date, datetime, time, timedelta
import pickle
import sys
import warnings

import numpy as np
import pytest
Expand Down Expand Up @@ -291,9 +292,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 warnings.catch_warnings(record=True) as w:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather use assert_produces_warning than custom code (and just disable the stack level check). pls also coment that the explict cast to object is causing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

warnings.simplefilter("always", FutureWarning)
df2.plot(ax=ax)
diffs = Series(ax.get_lines()[0].get_xydata()[:, 0]).diff()
assert (np.fabs(diffs[1:] - sec) < 1e-8).all()
match = (
"Automatically casting object-dtype Index of datetimes "
"to DatetimeIndex is deprecated"
)
assert match in str(w[0].message)

def test_irregular_datetime64_repr_bug(self):
ser = tm.makeTimeSeries()
Expand Down Expand Up @@ -1028,9 +1036,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 warnings.catch_warnings(record=True) as w:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as above

warnings.simplefilter("always", FutureWarning)
df = DataFrame(np.random.randn(len(idx), 3), idx)
_, ax = self.plt.subplots()
_check_plot_works(df.plot, ax=ax)
match = (
"Automatically casting object-dtype Index of datetimes "
"to DatetimeIndex is deprecated"
)
assert match in str(w[0].message)

@pytest.mark.slow
def test_time(self):
Expand Down