-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
BUG: record warnings related to DatetimeIndex #37193
Conversation
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: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment as above
thanks @ivanovmg |
I am not fully sure this is the correct way to deal with those warnings. So the warnings can be reproduced with this snippet:
In this case, the user is not doing any conversion of the index themselves, so at best the warning is quite confusing. Further, the question is if the behaviour will actually change once we enforce the deprecation. Because if not, then the warning is also useless (it's not warning about something that will change). |
there is an explicit astype here |
The warning is not coming from there, but from the plot() call. So yes it is plotting a dataframe with an object-dtype index. But 1) the warning is not clear about that and 2) we actually support plotting object dtype values, so there shouldn't necessarily be a warning at all. |
ok i guess - why don't u open a new issue this was just testing that we get a warning |
…)" This reverts commit 23c41bd.
…to DatetimeIndex in the Series constructor (23598)" (#38679) * Revert "DEPR: is_all_dates (#36697)" This reverts commit 90a6135. * revert Deprecated casting an object-dtype index of ``datetime`` objects to :class:`.DatetimeIndex` in the :class:`Series` constructor (:issue:`23598`) only * Revert "BUG: record warnings related to DatetimeIndex (#37193)" This reverts commit 23c41bd. * remove assert_produces_warning added in TST/REF: collect tests by method, some misplaced #37354
…to DatetimeIndex in the Series constructor (23598)" (pandas-dev#38679) * Revert "DEPR: is_all_dates (pandas-dev#36697)" This reverts commit 90a6135. * revert Deprecated casting an object-dtype index of ``datetime`` objects to :class:`.DatetimeIndex` in the :class:`Series` constructor (:issue:`23598`) only * Revert "BUG: record warnings related to DatetimeIndex (pandas-dev#37193)" This reverts commit 23c41bd. * remove assert_produces_warning added in TST/REF: collect tests by method, some misplaced pandas-dev#37354
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff
This PR handles warnings emitted when running tests in
pandas/tests/plotting/test_datetimelike.py
.Warnings looked like this:
Presumably it started after implementing this: #36697
The reason for not using
tm.assert_produces_warning
is that when I use it,then I get an error that the warning is raised with the incorrect stacklevel.