Skip to content
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

CI: Remove warning raising after new matplotlib release #31573

Merged
merged 16 commits into from
Feb 2, 2020
14 changes: 6 additions & 8 deletions pandas/tests/plotting/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import pandas._config.config as cf

from pandas.compat.numpy import np_datetime64_compat
import pandas.util._test_decorators as td

from pandas import Index, Period, Series, Timestamp, date_range
import pandas._testing as tm
Expand Down Expand Up @@ -59,16 +60,15 @@ def test_register_by_default(self):
call = [sys.executable, "-c", code]
assert subprocess.check_call(call) == 0

@td.skip_if_lower_3_1_2_mpl
def test_registering_no_warning(self):
plt = pytest.importorskip("matplotlib.pyplot")
s = Series(range(12), index=date_range("2017", periods=12))
_, ax = plt.subplots()

# Set to the "warn" state, in case this isn't the first test run
register_matplotlib_converters()
with tm.assert_produces_warning(DeprecationWarning, check_stacklevel=False):
# GH#30588 DeprecationWarning from 2D indexing
ax.plot(s.index, s.values)
ax.plot(s.index, s.values)

def test_pandas_plots_register(self):
pytest.importorskip("matplotlib.pyplot")
Expand All @@ -91,6 +91,7 @@ def test_matplotlib_formatters(self):
assert Timestamp not in units.registry
assert Timestamp in units.registry

@td.skip_if_lower_3_1_2_mpl
Copy link
Contributor

@jreback jreback Feb 2, 2020

Choose a reason for hiding this comment

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

sorry we don't really want to add this as a full decorator, just do this

@td.skip_if_no("matplotlib", min_version="3.1.2")

def test_option_no_warning(self):
pytest.importorskip("matplotlib.pyplot")
ctx = cf.option_context("plotting.matplotlib.register_converters", False)
Expand All @@ -100,15 +101,12 @@ def test_option_no_warning(self):

# Test without registering first, no warning
with ctx:
# GH#30588 DeprecationWarning from 2D indexing on Index
with tm.assert_produces_warning(DeprecationWarning, check_stacklevel=False):
ax.plot(s.index, s.values)
ax.plot(s.index, s.values)

# Now test with registering
register_matplotlib_converters()
with ctx:
with tm.assert_produces_warning(DeprecationWarning, check_stacklevel=False):
ax.plot(s.index, s.values)
ax.plot(s.index, s.values)

def test_registry_resets(self):
units = pytest.importorskip("matplotlib.units")
Expand Down
11 changes: 11 additions & 0 deletions pandas/util/_test_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ def _skip_if_no_scipy() -> bool:
)


def _skip_if_lower_3_1_2_mpl():
# GH 30588 matplotlib after 3.1.2 will no longer raise warning
# from 2D indexing on Index
mpl = safe_import("matplotlib")
return mpl and LooseVersion(mpl.__version__) <= LooseVersion("3.1.2")


def skip_if_installed(package: str) -> Callable:
"""
Skip a test if a package is installed.
Expand Down Expand Up @@ -194,6 +201,10 @@ def skip_if_no(package: str, min_version: Optional[str] = None) -> Callable:
not _USE_NUMEXPR,
reason=f"numexpr enabled->{_USE_NUMEXPR}, installed->{_NUMEXPR_INSTALLED}",
)
skip_if_lower_3_1_2_mpl = pytest.mark.skipif(
_skip_if_lower_3_1_2_mpl(),
reason="Matplotlib after 3.1.2 will no longer raise warning",
)


def skip_if_np_lt(
Expand Down