Skip to content

Commit 63616a6

Browse files
authored
TST: Don't mark all plotting tests as slow (#46003)
1 parent 6466fc6 commit 63616a6

19 files changed

+88
-72
lines changed

ci/run_tests.sh

-4
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ if [[ "$PATTERN" ]]; then
3030
PYTEST_CMD="$PYTEST_CMD -m \"$PATTERN\""
3131
fi
3232

33-
if [[ $(uname) != "Linux" && $(uname) != "Darwin" ]]; then
34-
PYTEST_CMD="$PYTEST_CMD --ignore=pandas/tests/plotting/"
35-
fi
36-
3733
echo $PYTEST_CMD
3834
sh -c "$PYTEST_CMD"
3935

pandas/plotting/_core.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -1793,12 +1793,19 @@ def _load_backend(backend: str) -> types.ModuleType:
17931793
found_backend = False
17941794

17951795
eps = entry_points()
1796-
if "pandas_plotting_backends" in eps:
1797-
for entry_point in eps["pandas_plotting_backends"]:
1798-
found_backend = entry_point.name == backend
1799-
if found_backend:
1800-
module = entry_point.load()
1801-
break
1796+
key = "pandas_plotting_backends"
1797+
# entry_points lost dict API ~ PY 3.10
1798+
# https://github.com/python/importlib_metadata/issues/298
1799+
if hasattr(eps, "select"):
1800+
# error: "Dict[str, Tuple[EntryPoint, ...]]" has no attribute "select"
1801+
entry = eps.select(group=key) # type: ignore[attr-defined]
1802+
else:
1803+
entry = eps.get(key, ())
1804+
for entry_point in entry:
1805+
found_backend = entry_point.name == backend
1806+
if found_backend:
1807+
module = entry_point.load()
1808+
break
18021809

18031810
if not found_backend:
18041811
# Fall back to unregistered, module name approach.

pandas/tests/plotting/common.py

-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
"""
22
Module consolidating common testing functions for checking plotting.
3-
4-
Currently all plotting tests are marked as slow via
5-
``pytestmark = pytest.mark.slow`` at the module level.
63
"""
74

85
from __future__ import annotations

pandas/tests/plotting/frame/test_frame.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,10 @@
3333
from pandas.io.formats.printing import pprint_thing
3434
import pandas.plotting as plotting
3535

36-
pytestmark = pytest.mark.slow
37-
3836

3937
@td.skip_if_no_mpl
4038
class TestDataFramePlots(TestPlotBase):
39+
@pytest.mark.slow
4140
def test_plot(self):
4241
df = tm.makeTimeDataFrame()
4342
_check_plot_works(df.plot, grid=False)
@@ -163,6 +162,7 @@ def test_nullable_int_plot(self):
163162
_check_plot_works(df[["A", "D"]].plot, x="A", y="D")
164163
_check_plot_works(df[["A", "E"]].plot, x="A", y="E")
165164

165+
@pytest.mark.slow
166166
def test_integer_array_plot(self):
167167
# GH 25587
168168
arr = pd.array([1, 2, 3, 4], dtype="UInt32")
@@ -787,6 +787,7 @@ def test_plot_scatter_with_s(self):
787787
ax = df.plot.scatter(x="a", y="b", s="c")
788788
tm.assert_numpy_array_equal(df["c"].values, right=ax.collections[0].get_sizes())
789789

790+
@pytest.mark.slow
790791
def test_plot_bar(self):
791792
df = DataFrame(
792793
np.random.randn(6, 4),
@@ -1416,6 +1417,7 @@ def test_pie_df_nan(self):
14161417
expected_labels = base_expected[:i] + base_expected[i + 1 :]
14171418
assert result_labels == expected_labels
14181419

1420+
@pytest.mark.slow
14191421
def test_errorbar_plot(self):
14201422
d = {"x": np.arange(12), "y": np.arange(12, 0, -1)}
14211423
df = DataFrame(d)
@@ -1462,6 +1464,7 @@ def test_errorbar_plot(self):
14621464
with tm.external_error_raised(TypeError):
14631465
df.plot(yerr=df_err)
14641466

1467+
@pytest.mark.slow
14651468
@pytest.mark.parametrize("kind", ["line", "bar", "barh"])
14661469
def test_errorbar_plot_different_kinds(self, kind):
14671470
d = {"x": np.arange(12), "y": np.arange(12, 0, -1)}
@@ -1513,6 +1516,7 @@ def test_errorbar_with_integer_column_names(self):
15131516
ax = _check_plot_works(df.plot, y=0, yerr=1)
15141517
self._check_has_errorbars(ax, xerr=0, yerr=1)
15151518

1519+
@pytest.mark.slow
15161520
def test_errorbar_with_partial_columns(self):
15171521
df = DataFrame(np.random.randn(10, 3))
15181522
df_err = DataFrame(np.random.randn(10, 2), columns=[0, 2])

pandas/tests/plotting/frame/test_frame_color.py

-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
_check_plot_works,
1616
)
1717

18-
pytestmark = pytest.mark.slow
19-
2018

2119
@td.skip_if_no_mpl
2220
class TestDataFrameColor(TestPlotBase):

pandas/tests/plotting/frame/test_frame_groupby.py

-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
from pandas import DataFrame
88
from pandas.tests.plotting.common import TestPlotBase
99

10-
pytestmark = pytest.mark.slow
11-
1210

1311
@td.skip_if_no_mpl
1412
class TestDataFramePlotsGroupby(TestPlotBase):

pandas/tests/plotting/frame/test_frame_legend.py

+17-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import numpy as np
22
import pytest
33

4+
import pandas.util._test_decorators as td
5+
46
from pandas import (
57
DataFrame,
68
date_range,
79
)
810
from pandas.tests.plotting.common import TestPlotBase
911

10-
pytestmark = pytest.mark.slow
11-
1212

1313
class TestFrameLegend(TestPlotBase):
1414
@pytest.mark.xfail(
@@ -45,6 +45,7 @@ def test_legend_false(self):
4545
expected = ["blue", "green", "red"]
4646
assert result == expected
4747

48+
@td.skip_if_no_scipy
4849
def test_df_legend_labels(self):
4950
kinds = ["line", "bar", "barh", "kde", "area", "hist"]
5051
df = DataFrame(np.random.rand(3, 3), columns=["a", "b", "c"])
@@ -158,13 +159,21 @@ def test_legend_name(self):
158159
leg_title = ax.legend_.get_title()
159160
self._check_text_labels(leg_title, "new")
160161

161-
def test_no_legend(self):
162-
kinds = ["line", "bar", "barh", "kde", "area", "hist"]
162+
@pytest.mark.parametrize(
163+
"kind",
164+
[
165+
"line",
166+
"bar",
167+
"barh",
168+
pytest.param("kde", marks=td.skip_if_no_scipy),
169+
"area",
170+
"hist",
171+
],
172+
)
173+
def test_no_legend(self, kind):
163174
df = DataFrame(np.random.rand(3, 3), columns=["a", "b", "c"])
164-
165-
for kind in kinds:
166-
ax = df.plot(kind=kind, legend=False)
167-
self._check_legend_labels(ax, visible=False)
175+
ax = df.plot(kind=kind, legend=False)
176+
self._check_legend_labels(ax, visible=False)
168177

169178
def test_missing_markers_legend(self):
170179
# 14958

pandas/tests/plotting/frame/test_frame_subplots.py

+15-13
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@
1919

2020
from pandas.io.formats.printing import pprint_thing
2121

22-
pytestmark = pytest.mark.slow
23-
2422

2523
@td.skip_if_no_mpl
2624
class TestDataFramePlotsSubplots(TestPlotBase):
25+
@pytest.mark.slow
2726
def test_subplots(self):
2827
df = DataFrame(np.random.rand(10, 3), index=list(string.ascii_letters[:10]))
2928

@@ -237,6 +236,7 @@ def test_subplots_layout_single_column(
237236
)
238237
assert axes.shape == expected_shape
239238

239+
@pytest.mark.slow
240240
def test_subplots_warnings(self):
241241
# GH 9464
242242
with tm.assert_produces_warning(None):
@@ -580,19 +580,21 @@ def test_bar_barwidth_position(self, kwargs):
580580
df = DataFrame(np.random.randn(5, 5))
581581
self._check_bar_alignment(df, width=0.9, position=0.2, **kwargs)
582582

583-
def test_bar_barwidth_position_int(self):
583+
@pytest.mark.parametrize("w", [1, 1.0])
584+
def test_bar_barwidth_position_int(self, w):
585+
# GH 12979
586+
df = DataFrame(np.random.randn(5, 5))
587+
ax = df.plot.bar(stacked=True, width=w)
588+
ticks = ax.xaxis.get_ticklocs()
589+
tm.assert_numpy_array_equal(ticks, np.array([0, 1, 2, 3, 4]))
590+
assert ax.get_xlim() == (-0.75, 4.75)
591+
# check left-edge of bars
592+
assert ax.patches[0].get_x() == -0.5
593+
assert ax.patches[-1].get_x() == 3.5
594+
595+
def test_bar_barwidth_position_int_width_1(self):
584596
# GH 12979
585597
df = DataFrame(np.random.randn(5, 5))
586-
587-
for w in [1, 1.0]:
588-
ax = df.plot.bar(stacked=True, width=w)
589-
ticks = ax.xaxis.get_ticklocs()
590-
tm.assert_numpy_array_equal(ticks, np.array([0, 1, 2, 3, 4]))
591-
assert ax.get_xlim() == (-0.75, 4.75)
592-
# check left-edge of bars
593-
assert ax.patches[0].get_x() == -0.5
594-
assert ax.patches[-1].get_x() == 3.5
595-
596598
self._check_bar_alignment(df, kind="bar", stacked=True, width=1)
597599
self._check_bar_alignment(df, kind="barh", stacked=False, width=1)
598600
self._check_bar_alignment(df, kind="barh", stacked=True, width=1)

pandas/tests/plotting/frame/test_hist_box_by.py

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def hist_df():
2424

2525
@td.skip_if_no_mpl
2626
class TestHistWithBy(TestPlotBase):
27+
@pytest.mark.slow
2728
@pytest.mark.parametrize(
2829
"by, column, titles, legends",
2930
[

pandas/tests/plotting/test_backend.py

-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
setattr(dummy_backend, "plot", lambda *args, **kwargs: "used_dummy")
1313

1414

15-
pytestmark = pytest.mark.slow
16-
17-
1815
@pytest.fixture
1916
def restore_backend():
2017
"""Restore the plotting backend to matplotlib"""

pandas/tests/plotting/test_boxplot_method.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
from pandas.io.formats.printing import pprint_thing
2525
import pandas.plotting as plotting
2626

27-
pytestmark = pytest.mark.slow
28-
2927

3028
@td.skip_if_no_mpl
3129
class TestDataFramePlots(TestPlotBase):
@@ -50,6 +48,7 @@ def test_stacked_boxplot_set_axis(self):
5048
np.arange(0, 80, 10)
5149
)
5250

51+
@pytest.mark.slow
5352
def test_boxplot_legacy1(self):
5453
df = DataFrame(
5554
np.random.randn(6, 4),
@@ -337,6 +336,7 @@ def test_boxplot_legacy1(self, hist_df):
337336
axes = _check_plot_works(grouped.boxplot, subplots=False, return_type="axes")
338337
self._check_axes_shape(axes, axes_num=1, layout=(1, 1))
339338

339+
@pytest.mark.slow
340340
def test_boxplot_legacy2(self):
341341
tuples = zip(string.ascii_letters[:10], range(10))
342342
df = DataFrame(np.random.rand(10, 3), index=MultiIndex.from_tuples(tuples))
@@ -381,6 +381,7 @@ def test_grouped_plot_fignums(self):
381381
res = df.groupby("gender").hist()
382382
tm.close()
383383

384+
@pytest.mark.slow
384385
def test_grouped_box_return_type(self, hist_df):
385386
df = hist_df
386387

@@ -415,6 +416,7 @@ def test_grouped_box_return_type(self, hist_df):
415416
returned = df2.boxplot(by="category", return_type=t)
416417
self._check_box_return_type(returned, t, expected_keys=columns2)
417418

419+
@pytest.mark.slow
418420
def test_grouped_box_layout(self, hist_df):
419421
df = hist_df
420422

@@ -508,6 +510,7 @@ def test_grouped_box_layout(self, hist_df):
508510
)
509511
self._check_axes_shape(self.plt.gcf().axes, axes_num=3, layout=(1, 3))
510512

513+
@pytest.mark.slow
511514
def test_grouped_box_multiple_axes(self, hist_df):
512515
# GH 6970, GH 7069
513516
df = hist_df

pandas/tests/plotting/test_common.py

-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
_gen_two_subplots,
1010
)
1111

12-
pytestmark = pytest.mark.slow
13-
1412

1513
@td.skip_if_no_mpl
1614
class TestCommon(TestPlotBase):

pandas/tests/plotting/test_converter.py

-3
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@
4343
dates = pytest.importorskip("matplotlib.dates")
4444

4545

46-
pytestmark = pytest.mark.slow
47-
48-
4946
def test_registry_mpl_resets():
5047
# Check that Matplotlib converters are properly reset (see issue #27481)
5148
code = (

pandas/tests/plotting/test_datetimelike.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,21 @@
4141

4242
from pandas.tseries.offsets import WeekOfMonth
4343

44-
pytestmark = pytest.mark.slow
45-
4644

4745
@td.skip_if_no_mpl
4846
class TestTSPlot(TestPlotBase):
47+
@pytest.mark.filterwarnings("ignore::UserWarning")
4948
def test_ts_plot_with_tz(self, tz_aware_fixture):
5049
# GH2877, GH17173, GH31205, GH31580
5150
tz = tz_aware_fixture
5251
index = date_range("1/1/2011", periods=2, freq="H", tz=tz)
5352
ts = Series([188.5, 328.25], index=index)
54-
with tm.assert_produces_warning(None):
55-
_check_plot_works(ts.plot)
56-
ax = ts.plot()
57-
xdata = list(ax.get_lines())[0].get_xdata()
58-
# Check first and last points' labels are correct
59-
assert (xdata[0].hour, xdata[0].minute) == (0, 0)
60-
assert (xdata[-1].hour, xdata[-1].minute) == (1, 0)
53+
_check_plot_works(ts.plot)
54+
ax = ts.plot()
55+
xdata = list(ax.get_lines())[0].get_xdata()
56+
# Check first and last points' labels are correct
57+
assert (xdata[0].hour, xdata[0].minute) == (0, 0)
58+
assert (xdata[-1].hour, xdata[-1].minute) == (1, 0)
6159

6260
def test_fontsize_set_correctly(self):
6361
# For issue #8765
@@ -497,6 +495,7 @@ def test_finder_annual(self):
497495

498496
assert rs == xp
499497

498+
@pytest.mark.slow
500499
def test_finder_minutely(self):
501500
nminutes = 50 * 24 * 60
502501
rng = date_range("1/1/1999", freq="Min", periods=nminutes)

pandas/tests/plotting/test_groupby.py

-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
import pandas._testing as tm
1515
from pandas.tests.plotting.common import TestPlotBase
1616

17-
pytestmark = pytest.mark.slow
18-
1917

2018
@td.skip_if_no_mpl
2119
class TestDataFrameGroupByPlots(TestPlotBase):

pandas/tests/plotting/test_hist_method.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
_check_plot_works,
1919
)
2020

21-
pytestmark = pytest.mark.slow
22-
2321

2422
@pytest.fixture
2523
def ts():
@@ -69,6 +67,7 @@ def test_hist_layout(self, hist_df):
6967
with pytest.raises(ValueError, match=msg):
7068
df.height.hist(layout=[1, 1])
7169

70+
@pytest.mark.slow
7271
def test_hist_layout_with_by(self, hist_df):
7372
df = hist_df
7473

@@ -232,6 +231,7 @@ def test_hist_kde_color(self, ts):
232231

233232
@td.skip_if_no_mpl
234233
class TestDataFramePlots(TestPlotBase):
234+
@pytest.mark.slow
235235
def test_hist_df_legacy(self, hist_df):
236236
from matplotlib.patches import Rectangle
237237

@@ -644,6 +644,7 @@ def test_grouped_hist_legacy2(self):
644644
assert len(self.plt.get_fignums()) == 2
645645
tm.close()
646646

647+
@pytest.mark.slow
647648
def test_grouped_hist_layout(self, hist_df):
648649
df = hist_df
649650
msg = "Layout of 1x1 must be larger than required size 2"

0 commit comments

Comments
 (0)