Skip to content

Commit 0fb4854

Browse files
committed
TST: Patch Circle matplotlib failure
The tm.mplskip decorator was breaking on Circle, so this commit removes the decorator and replaces it with direct function calls to check for matplotlib.
1 parent e0284e4 commit 0fb4854

11 files changed

+33
-34
lines changed

pandas/tests/io/formats/test_style.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55
import numpy as np
66
import pandas as pd
77
from pandas import DataFrame
8-
from pandas.util.testing import TestCase
98
import pandas.util.testing as tm
109

1110
jinja2 = pytest.importorskip('jinja2')
1211
from pandas.io.formats.style import Styler, _get_level_lengths # noqa
1312

1413

15-
class TestStyler(TestCase):
14+
class TestStyler(tm.TestCase):
1615

1716
def setup_method(self, method):
1817
np.random.seed(24)
@@ -813,10 +812,10 @@ def test_mi_sparse_column_names(self):
813812
assert head == expected
814813

815814

816-
@tm.mplskip
817-
class TestStylerMatplotlibDep(TestCase):
815+
class TestStylerMatplotlibDep(tm.TestCase):
818816

819817
def test_background_gradient(self):
818+
tm._skip_if_no_mpl()
820819
df = pd.DataFrame([[1, 2], [2, 4]], columns=['A', 'B'])
821820

822821
for c_map in [None, 'YlOrRd']:

pandas/tests/plotting/common.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919
import pandas.plotting as plotting
2020
from pandas.plotting._tools import _flatten
2121

22-
2322
"""
2423
This is a common base class used for various plotting tests
2524
"""
2625

26+
tm._skip_module_if_no_mpl()
27+
2728

2829
def _skip_if_no_scipy_gaussian_kde():
2930
try:
@@ -41,7 +42,6 @@ def _ok_for_gaussian_kde(kind):
4142
return True
4243

4344

44-
@tm.mplskip
4545
class TestPlotBase(tm.TestCase):
4646

4747
def setup_method(self, method):

pandas/tests/plotting/test_boxplot_method.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
""" Test cases for .boxplot method """
2323

24+
tm._skip_module_if_no_mpl()
25+
2426

2527
def _skip_if_mpl_14_or_dev_boxplot():
2628
# GH 8382
@@ -31,7 +33,6 @@ def _skip_if_mpl_14_or_dev_boxplot():
3133
pytest.skip("Matplotlib Regression in 1.4 and current dev.")
3234

3335

34-
@tm.mplskip
3536
class TestDataFramePlots(TestPlotBase):
3637

3738
@slow
@@ -165,7 +166,6 @@ def test_fontsize(self):
165166
xlabelsize=16, ylabelsize=16)
166167

167168

168-
@tm.mplskip
169169
class TestDataFrameGroupByPlots(TestPlotBase):
170170

171171
@slow

pandas/tests/plotting/test_datetimelike.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
from pandas.tests.plotting.common import (TestPlotBase,
2121
_skip_if_no_scipy_gaussian_kde)
2222

23+
tm._skip_module_if_no_mpl()
24+
2325

24-
@tm.mplskip
2526
class TestTSPlot(TestPlotBase):
2627

2728
def setup_method(self, method):

pandas/tests/plotting/test_deprecated.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
pandas.tools.plotting
1919
"""
2020

21+
tm._skip_module_if_no_mpl()
22+
2123

22-
@tm.mplskip
2324
class TestDeprecatedNameSpace(TestPlotBase):
2425

2526
@slow

pandas/tests/plotting/test_frame.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@
2727
_skip_if_no_scipy_gaussian_kde,
2828
_ok_for_gaussian_kde)
2929

30+
tm._skip_module_if_no_mpl()
31+
3032

31-
@tm.mplskip
3233
class TestDataFramePlots(TestPlotBase):
3334

3435
def setup_method(self, method):

pandas/tests/plotting/test_groupby.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010

1111
from pandas.tests.plotting.common import TestPlotBase
1212

13+
tm._skip_module_if_no_mpl()
14+
1315

14-
@tm.mplskip
1516
class TestDataFrameGroupByPlots(TestPlotBase):
1617

1718
def test_series_groupby_plotting_nominally_works(self):

pandas/tests/plotting/test_hist_method.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
from pandas.tests.plotting.common import (TestPlotBase, _check_plot_works)
1616

1717

18-
@tm.mplskip
18+
tm._skip_module_if_no_mpl()
19+
20+
1921
class TestSeriesPlots(TestPlotBase):
2022

2123
def setup_method(self, method):
@@ -140,7 +142,6 @@ def test_plot_fails_when_ax_differs_from_figure(self):
140142
self.ts.hist(ax=ax1, figure=fig2)
141143

142144

143-
@tm.mplskip
144145
class TestDataFramePlots(TestPlotBase):
145146

146147
@slow
@@ -251,7 +252,6 @@ def test_tight_layout(self):
251252
tm.close()
252253

253254

254-
@tm.mplskip
255255
class TestDataFrameGroupByPlots(TestPlotBase):
256256

257257
@slow

pandas/tests/plotting/test_misc.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
from pandas.tests.plotting.common import (TestPlotBase, _check_plot_works,
1818
_ok_for_gaussian_kde)
1919

20+
tm._skip_module_if_no_mpl()
21+
2022

21-
@tm.mplskip
2223
class TestSeriesPlots(TestPlotBase):
2324

2425
def setup_method(self, method):
@@ -50,7 +51,6 @@ def test_bootstrap_plot(self):
5051
_check_plot_works(bootstrap_plot, series=self.ts, size=10)
5152

5253

53-
@tm.mplskip
5454
class TestDataFramePlots(TestPlotBase):
5555

5656
@slow

pandas/tests/plotting/test_series.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
_skip_if_no_scipy_gaussian_kde,
2323
_ok_for_gaussian_kde)
2424

25+
tm._skip_module_if_no_mpl()
26+
2527

26-
@tm.mplskip
2728
class TestSeriesPlots(TestPlotBase):
2829

2930
def setup_method(self, method):

pandas/util/testing.py

+11-16
Original file line numberDiff line numberDiff line change
@@ -289,36 +289,31 @@ def _skip_if_32bit():
289289
pytest.skip("skipping for 32 bit")
290290

291291

292-
def mplskip(cls):
293-
"""Skip a TestCase instance if matplotlib isn't installed"""
294-
295-
@classmethod
296-
def setup_class(cls):
297-
try:
298-
import matplotlib as mpl
299-
mpl.use("Agg", warn=False)
300-
except ImportError:
301-
import pytest
302-
pytest.skip("matplotlib not installed")
292+
def _skip_module_if_no_mpl():
293+
import pytest
303294

304-
cls.setup_class = setup_class
305-
return cls
295+
mpl = pytest.importorskip("matplotlib")
296+
mpl.use("Agg", warn=False)
306297

307298

308299
def _skip_if_no_mpl():
309300
try:
310-
import matplotlib # noqa
301+
import matplotlib as mpl
302+
mpl.use("Agg", warn=False)
311303
except ImportError:
312304
import pytest
313305
pytest.skip("matplotlib not installed")
314306

315307

316308
def _skip_if_mpl_1_5():
317-
import matplotlib
318-
v = matplotlib.__version__
309+
import matplotlib as mpl
310+
311+
v = mpl.__version__
319312
if v > LooseVersion('1.4.3') or v[0] == '0':
320313
import pytest
321314
pytest.skip("matplotlib 1.5")
315+
else:
316+
mpl.use("Agg", warn=False)
322317

323318

324319
def _skip_if_no_scipy():

0 commit comments

Comments
 (0)