Skip to content

FIX: fix cleanup warnings for errorbar timeseries #36982

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

Conversation

ivanovmg
Copy link
Member

@ivanovmg ivanovmg commented Oct 8, 2020

  • closes #xxxx
  • tests added / passed
  • passes black pandas
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff
  • whatsnew entry

Currently in pandas/tests/plotting/tests_frame.py there are several warnings emitted.

pandas/tests/plotting/test_frame.py::TestDataFramePlots::test_mpl2_color_cycle_str
  /workspaces/pandas/pandas/plotting/_matplotlib/style.py:64: MatplotlibDeprecationWarning: Support for uppercase single-letter colors is deprecated since Matplotlib 3.1 and will be removed in 3.3; please use lowercase instead.
    [conv.to_rgba(c) for c in colors]

pandas/tests/plotting/test_frame.py::TestDataFramePlots::test_errorbar_plot
pandas/tests/plotting/test_frame.py::TestDataFramePlots::test_errorbar_plot
pandas/tests/plotting/test_frame.py::TestDataFramePlots::test_errorbar_plot
pandas/tests/plotting/test_frame.py::TestDataFramePlots::test_errorbar_timeseries
pandas/tests/plotting/test_frame.py::TestDataFramePlots::test_errorbar_timeseries
pandas/tests/plotting/test_frame.py::TestDataFramePlots::test_errorbar_timeseries
  /workspaces/pandas/pandas/plotting/_matplotlib/__init__.py:61: UserWarning: To output multiple subplots, the figure containing the passed axes is being cleared
    plot_obj.generate()

-- Docs: https://docs.pytest.org/en/stable/warnings.html

This PR handles warnings in test_errorbar_timeseries.
If this approach is considered reasonable by the reviewers, then I will do the same for test_errorbar_plot as well as other similar warnings among the plotting-related tests.

@jreback
Copy link
Contributor

jreback commented Oct 8, 2020

so the test itself was causing the warnings?

@jreback jreback added Visualization plotting Clean Testing pandas testing functions or related to the test suite labels Oct 8, 2020
@jreback
Copy link
Contributor

jreback commented Oct 8, 2020

cc @charlesdong1991

@ivanovmg
Copy link
Member Author

ivanovmg commented Oct 9, 2020

so the test itself was causing the warnings?

Yes, the test itself was causing the warning.

@charlesdong1991
Copy link
Member

charlesdong1991 commented Oct 9, 2020

this reminds me of this #13188 issue, the warning and the issue looks the same, should we use with tm.assert_produces_warning(UserWarning): to catch the part where subplots=True, something like this? and remove the catch_warning on the very top?

with tm.assert_produces_warning(UserWarning):
    axes = _check_plot_works(tdf.plot, kind=kind, yerr=tdf_err, subplots=True)
    self._check_has_errorbars(axes, xerr=0, yerr=1)

@ivanovmg
Copy link
Member Author

ivanovmg commented Oct 9, 2020

this reminds me of this #13188 issue, the warning looks the same, should we use with tm.assert_produces_warning(UserWarning): to catch the part where subplots=True? or we should also use the same solution here to replace these warnings?

I did not use tm.assert_produces_warning because there is no way to match warning message this way.
I believe it is reasonable to match the message here.
What would others think?

@charlesdong1991
Copy link
Member

true, I would suggest to use tm.assert_produce_warning here to align with other existing similar issue, and see if we could add an arg for tm.assert_produce_warning to also match the warning message (I haven't looked at how this function is structured, not sure if it's easy or not to add such match), and then do a small refactor to match the warning message in these places.

does it sound good to you?

@ivanovmg
Copy link
Member Author

ivanovmg commented Oct 9, 2020

true, I would suggest to use tm.assert_produce_warning here to align with other existing similar issue, and see if we could add an arg for tm.assert_produce_warning to also match the warning message (I haven't looked at how this function is structured, not sure if it's easy or not to add such match), and then do a small refactor to match the warning message in these places.

does it sound good to you?

Absolutely, I will refactor to tm.assert_produces_warning and add a comment what kind of warning message is expected.
Then in a follow-on PR I can take a look at the extension of tm.assert_produces_warning to match messages.
I believe that extension of tm.assert_produces_warning goes beyond the scope of the present PR.

@charlesdong1991
Copy link
Member

yep! sounds good!

you could use use tm.assert_produce_warning in this PR and add a comment to refer to the original 13188, so later could easily catch them! Please also do it for test_errorbar_plot test as well!

I believe that extension of tm.assert_produces_warning goes beyond the scope of the present PR.

yeah, a follow-up would be great!

As agreed with charlesdong1991,
use assert_produces_warning
and leave a comment on which warning message is emitted
Extract test_errorbar_plot_different_kinds
from test_errorbar_plot and parametrize it.
@ivanovmg ivanovmg force-pushed the warnings/matplotlib-errorbar-timeseries branch from 8501cd3 to d5a9e5e Compare October 9, 2020 07:41
@ivanovmg
Copy link
Member Author

ivanovmg commented Oct 9, 2020

Did that. But also I decided to move from test_errorbar_plot part related to various kinds in a separate parametrize test. Can revert it if this is not suitable. But to me it seems that in general it would be required to split some test functions into smaller ones with more relevant names.

@charlesdong1991
Copy link
Member

I decided to move from test_errorbar_plot part related to various kinds in a separate parametrize test

sure!

Copy link
Member

@charlesdong1991 charlesdong1991 left a comment

Choose a reason for hiding this comment

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

very nice!

could you double check that after this change, the warnings you post in the PR description are gone?

cc @jreback

Comment on lines 2823 to 2826
_check_plot_works(tdf.plot, kind=kind, yerr=tdf_err, subplots=True)
fig = plt.gcf()
axes = fig.get_axes()
for ax in axes:
Copy link
Member

Choose a reason for hiding this comment

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

sorry, just noticed this, a minor question:

i think with tm.assert_produce_warning, we could still use the current way to check errorbars, right? _check_has_errorbars i recall can take in axes/list-like input.

axes = _check_plot_works(	
                    tdf.plot, kind=kind, yerr=tdf_err, subplots=True	
                )
self._check_has_errorbars(axes, xerr=0, yerr=1)

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, yes, it does accept list-like. I will change to the original implementation.

@ivanovmg
Copy link
Member Author

ivanovmg commented Oct 9, 2020

I checked.
Here is the output.

(base) root@f31dd4516194:/workspaces/pandas# pytest pandas/tests/plotting/test_frame.py
======================================================================================================================== test session starts =========================================================================================================================
platform linux -- Python 3.7.7, pytest-6.0.1, py-1.9.0, pluggy-0.13.1
rootdir: /workspaces/pandas, configfile: setup.cfg
plugins: cov-2.10.0, forked-1.2.0, xdist-1.34.0, hypothesis-5.23.11, asyncio-0.12.0
collected 191 items                                                                                                                                                                                                                                                  

pandas/tests/plotting/test_frame.py ...........................x....................................................................................................x..............................................................                            [100%]

========================================================================================================================== warnings summary ==========================================================================================================================
pandas/tests/plotting/test_frame.py::TestDataFramePlots::test_mpl2_color_cycle_str
  /workspaces/pandas/pandas/plotting/_matplotlib/style.py:64: MatplotlibDeprecationWarning: Support for uppercase single-letter colors is deprecated since Matplotlib 3.1 and will be removed in 3.3; please use lowercase instead.
    [conv.to_rgba(c) for c in colors]

-- Docs: https://docs.pytest.org/en/stable/warnings.html
======================================================================================================== 189 passed, 2 xfailed, 1 warning in 64.14s (0:01:04) ========================================================================================================
(base) root@f31dd4516194:/workspaces/pandas#

Another warning is handled in #36981

@charlesdong1991 charlesdong1991 added this to the 1.2 milestone Oct 9, 2020
@jreback jreback merged commit 9425d7c into pandas-dev:master Oct 10, 2020
@jreback
Copy link
Contributor

jreback commented Oct 10, 2020

thanks @ivanovmg

@ivanovmg ivanovmg deleted the warnings/matplotlib-errorbar-timeseries branch October 10, 2020 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Clean Testing pandas testing functions or related to the test suite Visualization plotting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants