diff --git a/ci/run_tests.sh b/ci/run_tests.sh index 7c11eb13e0e1d..aa6bb714af9dd 100755 --- a/ci/run_tests.sh +++ b/ci/run_tests.sh @@ -30,10 +30,6 @@ if [[ "$PATTERN" ]]; then PYTEST_CMD="$PYTEST_CMD -m \"$PATTERN\"" fi -if [[ $(uname) != "Linux" && $(uname) != "Darwin" ]]; then - PYTEST_CMD="$PYTEST_CMD --ignore=pandas/tests/plotting/" -fi - echo $PYTEST_CMD sh -c "$PYTEST_CMD" diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index 216ccddcf05cb..85bc3121f5e4e 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -1793,12 +1793,19 @@ def _load_backend(backend: str) -> types.ModuleType: found_backend = False eps = entry_points() - if "pandas_plotting_backends" in eps: - for entry_point in eps["pandas_plotting_backends"]: - found_backend = entry_point.name == backend - if found_backend: - module = entry_point.load() - break + key = "pandas_plotting_backends" + # entry_points lost dict API ~ PY 3.10 + # https://github.com/python/importlib_metadata/issues/298 + if hasattr(eps, "select"): + # error: "Dict[str, Tuple[EntryPoint, ...]]" has no attribute "select" + entry = eps.select(group=key) # type: ignore[attr-defined] + else: + entry = eps.get(key, ()) + for entry_point in entry: + found_backend = entry_point.name == backend + if found_backend: + module = entry_point.load() + break if not found_backend: # Fall back to unregistered, module name approach. diff --git a/pandas/tests/plotting/common.py b/pandas/tests/plotting/common.py index 1e91379921b88..df853770b85f1 100644 --- a/pandas/tests/plotting/common.py +++ b/pandas/tests/plotting/common.py @@ -1,8 +1,5 @@ """ Module consolidating common testing functions for checking plotting. - -Currently all plotting tests are marked as slow via -``pytestmark = pytest.mark.slow`` at the module level. """ from __future__ import annotations diff --git a/pandas/tests/plotting/frame/test_frame.py b/pandas/tests/plotting/frame/test_frame.py index 9861c84b7cc03..818c86dfca424 100644 --- a/pandas/tests/plotting/frame/test_frame.py +++ b/pandas/tests/plotting/frame/test_frame.py @@ -33,11 +33,10 @@ from pandas.io.formats.printing import pprint_thing import pandas.plotting as plotting -pytestmark = pytest.mark.slow - @td.skip_if_no_mpl class TestDataFramePlots(TestPlotBase): + @pytest.mark.slow def test_plot(self): df = tm.makeTimeDataFrame() _check_plot_works(df.plot, grid=False) @@ -163,6 +162,7 @@ def test_nullable_int_plot(self): _check_plot_works(df[["A", "D"]].plot, x="A", y="D") _check_plot_works(df[["A", "E"]].plot, x="A", y="E") + @pytest.mark.slow def test_integer_array_plot(self): # GH 25587 arr = pd.array([1, 2, 3, 4], dtype="UInt32") @@ -787,6 +787,7 @@ def test_plot_scatter_with_s(self): ax = df.plot.scatter(x="a", y="b", s="c") tm.assert_numpy_array_equal(df["c"].values, right=ax.collections[0].get_sizes()) + @pytest.mark.slow def test_plot_bar(self): df = DataFrame( np.random.randn(6, 4), @@ -1416,6 +1417,7 @@ def test_pie_df_nan(self): expected_labels = base_expected[:i] + base_expected[i + 1 :] assert result_labels == expected_labels + @pytest.mark.slow def test_errorbar_plot(self): d = {"x": np.arange(12), "y": np.arange(12, 0, -1)} df = DataFrame(d) @@ -1462,6 +1464,7 @@ def test_errorbar_plot(self): with tm.external_error_raised(TypeError): df.plot(yerr=df_err) + @pytest.mark.slow @pytest.mark.parametrize("kind", ["line", "bar", "barh"]) def test_errorbar_plot_different_kinds(self, kind): d = {"x": np.arange(12), "y": np.arange(12, 0, -1)} @@ -1513,6 +1516,7 @@ def test_errorbar_with_integer_column_names(self): ax = _check_plot_works(df.plot, y=0, yerr=1) self._check_has_errorbars(ax, xerr=0, yerr=1) + @pytest.mark.slow def test_errorbar_with_partial_columns(self): df = DataFrame(np.random.randn(10, 3)) df_err = DataFrame(np.random.randn(10, 2), columns=[0, 2]) diff --git a/pandas/tests/plotting/frame/test_frame_color.py b/pandas/tests/plotting/frame/test_frame_color.py index 867570b06ff31..ed0c94aa4dfa0 100644 --- a/pandas/tests/plotting/frame/test_frame_color.py +++ b/pandas/tests/plotting/frame/test_frame_color.py @@ -15,8 +15,6 @@ _check_plot_works, ) -pytestmark = pytest.mark.slow - @td.skip_if_no_mpl class TestDataFrameColor(TestPlotBase): diff --git a/pandas/tests/plotting/frame/test_frame_groupby.py b/pandas/tests/plotting/frame/test_frame_groupby.py index e18bdbc5d7579..9c148645966ad 100644 --- a/pandas/tests/plotting/frame/test_frame_groupby.py +++ b/pandas/tests/plotting/frame/test_frame_groupby.py @@ -7,8 +7,6 @@ from pandas import DataFrame from pandas.tests.plotting.common import TestPlotBase -pytestmark = pytest.mark.slow - @td.skip_if_no_mpl class TestDataFramePlotsGroupby(TestPlotBase): diff --git a/pandas/tests/plotting/frame/test_frame_legend.py b/pandas/tests/plotting/frame/test_frame_legend.py index 9501047415e9e..e11aeeccfd5fb 100644 --- a/pandas/tests/plotting/frame/test_frame_legend.py +++ b/pandas/tests/plotting/frame/test_frame_legend.py @@ -1,14 +1,14 @@ import numpy as np import pytest +import pandas.util._test_decorators as td + from pandas import ( DataFrame, date_range, ) from pandas.tests.plotting.common import TestPlotBase -pytestmark = pytest.mark.slow - class TestFrameLegend(TestPlotBase): @pytest.mark.xfail( @@ -45,6 +45,7 @@ def test_legend_false(self): expected = ["blue", "green", "red"] assert result == expected + @td.skip_if_no_scipy def test_df_legend_labels(self): kinds = ["line", "bar", "barh", "kde", "area", "hist"] df = DataFrame(np.random.rand(3, 3), columns=["a", "b", "c"]) @@ -158,13 +159,21 @@ def test_legend_name(self): leg_title = ax.legend_.get_title() self._check_text_labels(leg_title, "new") - def test_no_legend(self): - kinds = ["line", "bar", "barh", "kde", "area", "hist"] + @pytest.mark.parametrize( + "kind", + [ + "line", + "bar", + "barh", + pytest.param("kde", marks=td.skip_if_no_scipy), + "area", + "hist", + ], + ) + def test_no_legend(self, kind): df = DataFrame(np.random.rand(3, 3), columns=["a", "b", "c"]) - - for kind in kinds: - ax = df.plot(kind=kind, legend=False) - self._check_legend_labels(ax, visible=False) + ax = df.plot(kind=kind, legend=False) + self._check_legend_labels(ax, visible=False) def test_missing_markers_legend(self): # 14958 diff --git a/pandas/tests/plotting/frame/test_frame_subplots.py b/pandas/tests/plotting/frame/test_frame_subplots.py index 4805eb558c465..47d91c7975a28 100644 --- a/pandas/tests/plotting/frame/test_frame_subplots.py +++ b/pandas/tests/plotting/frame/test_frame_subplots.py @@ -19,11 +19,10 @@ from pandas.io.formats.printing import pprint_thing -pytestmark = pytest.mark.slow - @td.skip_if_no_mpl class TestDataFramePlotsSubplots(TestPlotBase): + @pytest.mark.slow def test_subplots(self): df = DataFrame(np.random.rand(10, 3), index=list(string.ascii_letters[:10])) @@ -237,6 +236,7 @@ def test_subplots_layout_single_column( ) assert axes.shape == expected_shape + @pytest.mark.slow def test_subplots_warnings(self): # GH 9464 with tm.assert_produces_warning(None): @@ -580,19 +580,21 @@ def test_bar_barwidth_position(self, kwargs): df = DataFrame(np.random.randn(5, 5)) self._check_bar_alignment(df, width=0.9, position=0.2, **kwargs) - def test_bar_barwidth_position_int(self): + @pytest.mark.parametrize("w", [1, 1.0]) + def test_bar_barwidth_position_int(self, w): + # GH 12979 + df = DataFrame(np.random.randn(5, 5)) + ax = df.plot.bar(stacked=True, width=w) + ticks = ax.xaxis.get_ticklocs() + tm.assert_numpy_array_equal(ticks, np.array([0, 1, 2, 3, 4])) + assert ax.get_xlim() == (-0.75, 4.75) + # check left-edge of bars + assert ax.patches[0].get_x() == -0.5 + assert ax.patches[-1].get_x() == 3.5 + + def test_bar_barwidth_position_int_width_1(self): # GH 12979 df = DataFrame(np.random.randn(5, 5)) - - for w in [1, 1.0]: - ax = df.plot.bar(stacked=True, width=w) - ticks = ax.xaxis.get_ticklocs() - tm.assert_numpy_array_equal(ticks, np.array([0, 1, 2, 3, 4])) - assert ax.get_xlim() == (-0.75, 4.75) - # check left-edge of bars - assert ax.patches[0].get_x() == -0.5 - assert ax.patches[-1].get_x() == 3.5 - self._check_bar_alignment(df, kind="bar", stacked=True, width=1) self._check_bar_alignment(df, kind="barh", stacked=False, width=1) self._check_bar_alignment(df, kind="barh", stacked=True, width=1) diff --git a/pandas/tests/plotting/frame/test_hist_box_by.py b/pandas/tests/plotting/frame/test_hist_box_by.py index 282c977f89552..fe39c3d441396 100644 --- a/pandas/tests/plotting/frame/test_hist_box_by.py +++ b/pandas/tests/plotting/frame/test_hist_box_by.py @@ -24,6 +24,7 @@ def hist_df(): @td.skip_if_no_mpl class TestHistWithBy(TestPlotBase): + @pytest.mark.slow @pytest.mark.parametrize( "by, column, titles, legends", [ diff --git a/pandas/tests/plotting/test_backend.py b/pandas/tests/plotting/test_backend.py index 1e3635714b745..82e82781e894b 100644 --- a/pandas/tests/plotting/test_backend.py +++ b/pandas/tests/plotting/test_backend.py @@ -12,9 +12,6 @@ setattr(dummy_backend, "plot", lambda *args, **kwargs: "used_dummy") -pytestmark = pytest.mark.slow - - @pytest.fixture def restore_backend(): """Restore the plotting backend to matplotlib""" diff --git a/pandas/tests/plotting/test_boxplot_method.py b/pandas/tests/plotting/test_boxplot_method.py index 207ebd7f2a193..9ca8a71ed1897 100644 --- a/pandas/tests/plotting/test_boxplot_method.py +++ b/pandas/tests/plotting/test_boxplot_method.py @@ -24,8 +24,6 @@ from pandas.io.formats.printing import pprint_thing import pandas.plotting as plotting -pytestmark = pytest.mark.slow - @td.skip_if_no_mpl class TestDataFramePlots(TestPlotBase): @@ -50,6 +48,7 @@ def test_stacked_boxplot_set_axis(self): np.arange(0, 80, 10) ) + @pytest.mark.slow def test_boxplot_legacy1(self): df = DataFrame( np.random.randn(6, 4), @@ -337,6 +336,7 @@ def test_boxplot_legacy1(self, hist_df): axes = _check_plot_works(grouped.boxplot, subplots=False, return_type="axes") self._check_axes_shape(axes, axes_num=1, layout=(1, 1)) + @pytest.mark.slow def test_boxplot_legacy2(self): tuples = zip(string.ascii_letters[:10], range(10)) df = DataFrame(np.random.rand(10, 3), index=MultiIndex.from_tuples(tuples)) @@ -381,6 +381,7 @@ def test_grouped_plot_fignums(self): res = df.groupby("gender").hist() tm.close() + @pytest.mark.slow def test_grouped_box_return_type(self, hist_df): df = hist_df @@ -415,6 +416,7 @@ def test_grouped_box_return_type(self, hist_df): returned = df2.boxplot(by="category", return_type=t) self._check_box_return_type(returned, t, expected_keys=columns2) + @pytest.mark.slow def test_grouped_box_layout(self, hist_df): df = hist_df @@ -508,6 +510,7 @@ def test_grouped_box_layout(self, hist_df): ) self._check_axes_shape(self.plt.gcf().axes, axes_num=3, layout=(1, 3)) + @pytest.mark.slow def test_grouped_box_multiple_axes(self, hist_df): # GH 6970, GH 7069 df = hist_df diff --git a/pandas/tests/plotting/test_common.py b/pandas/tests/plotting/test_common.py index 6eebf0c01ae52..d4624cfc74872 100644 --- a/pandas/tests/plotting/test_common.py +++ b/pandas/tests/plotting/test_common.py @@ -9,8 +9,6 @@ _gen_two_subplots, ) -pytestmark = pytest.mark.slow - @td.skip_if_no_mpl class TestCommon(TestPlotBase): diff --git a/pandas/tests/plotting/test_converter.py b/pandas/tests/plotting/test_converter.py index f3418415695b0..04d3397faddb7 100644 --- a/pandas/tests/plotting/test_converter.py +++ b/pandas/tests/plotting/test_converter.py @@ -43,9 +43,6 @@ dates = pytest.importorskip("matplotlib.dates") -pytestmark = pytest.mark.slow - - def test_registry_mpl_resets(): # Check that Matplotlib converters are properly reset (see issue #27481) code = ( diff --git a/pandas/tests/plotting/test_datetimelike.py b/pandas/tests/plotting/test_datetimelike.py index 197083a9ad940..9b08cd0637751 100644 --- a/pandas/tests/plotting/test_datetimelike.py +++ b/pandas/tests/plotting/test_datetimelike.py @@ -41,23 +41,21 @@ from pandas.tseries.offsets import WeekOfMonth -pytestmark = pytest.mark.slow - @td.skip_if_no_mpl class TestTSPlot(TestPlotBase): + @pytest.mark.filterwarnings("ignore::UserWarning") def test_ts_plot_with_tz(self, tz_aware_fixture): # GH2877, GH17173, GH31205, GH31580 tz = tz_aware_fixture index = date_range("1/1/2011", periods=2, freq="H", tz=tz) ts = Series([188.5, 328.25], index=index) - with tm.assert_produces_warning(None): - _check_plot_works(ts.plot) - ax = ts.plot() - xdata = list(ax.get_lines())[0].get_xdata() - # Check first and last points' labels are correct - assert (xdata[0].hour, xdata[0].minute) == (0, 0) - assert (xdata[-1].hour, xdata[-1].minute) == (1, 0) + _check_plot_works(ts.plot) + ax = ts.plot() + xdata = list(ax.get_lines())[0].get_xdata() + # Check first and last points' labels are correct + assert (xdata[0].hour, xdata[0].minute) == (0, 0) + assert (xdata[-1].hour, xdata[-1].minute) == (1, 0) def test_fontsize_set_correctly(self): # For issue #8765 @@ -497,6 +495,7 @@ def test_finder_annual(self): assert rs == xp + @pytest.mark.slow def test_finder_minutely(self): nminutes = 50 * 24 * 60 rng = date_range("1/1/1999", freq="Min", periods=nminutes) diff --git a/pandas/tests/plotting/test_groupby.py b/pandas/tests/plotting/test_groupby.py index 997f5abe12078..de81ad20f7370 100644 --- a/pandas/tests/plotting/test_groupby.py +++ b/pandas/tests/plotting/test_groupby.py @@ -14,8 +14,6 @@ import pandas._testing as tm from pandas.tests.plotting.common import TestPlotBase -pytestmark = pytest.mark.slow - @td.skip_if_no_mpl class TestDataFrameGroupByPlots(TestPlotBase): diff --git a/pandas/tests/plotting/test_hist_method.py b/pandas/tests/plotting/test_hist_method.py index c2926b4f22372..0955e7808f3f6 100644 --- a/pandas/tests/plotting/test_hist_method.py +++ b/pandas/tests/plotting/test_hist_method.py @@ -18,8 +18,6 @@ _check_plot_works, ) -pytestmark = pytest.mark.slow - @pytest.fixture def ts(): @@ -69,6 +67,7 @@ def test_hist_layout(self, hist_df): with pytest.raises(ValueError, match=msg): df.height.hist(layout=[1, 1]) + @pytest.mark.slow def test_hist_layout_with_by(self, hist_df): df = hist_df @@ -232,6 +231,7 @@ def test_hist_kde_color(self, ts): @td.skip_if_no_mpl class TestDataFramePlots(TestPlotBase): + @pytest.mark.slow def test_hist_df_legacy(self, hist_df): from matplotlib.patches import Rectangle @@ -644,6 +644,7 @@ def test_grouped_hist_legacy2(self): assert len(self.plt.get_fignums()) == 2 tm.close() + @pytest.mark.slow def test_grouped_hist_layout(self, hist_df): df = hist_df msg = "Layout of 1x1 must be larger than required size 2" diff --git a/pandas/tests/plotting/test_misc.py b/pandas/tests/plotting/test_misc.py index be5e5cbae2538..64c736d6314e4 100644 --- a/pandas/tests/plotting/test_misc.py +++ b/pandas/tests/plotting/test_misc.py @@ -17,8 +17,6 @@ import pandas.plotting as plotting -pytestmark = pytest.mark.slow - @td.skip_if_mpl def test_import_error_message(): @@ -137,6 +135,7 @@ def test_scatter_matrix_axis(self, pass_axis): self._check_text_labels(axes0_labels, expected) self._check_ticks_props(axes, xlabelsize=8, xrot=90, ylabelsize=8, yrot=0) + @pytest.mark.slow def test_andrews_curves(self, iris): from matplotlib import cm @@ -213,6 +212,7 @@ def test_andrews_curves(self, iris): handles, labels = ax.get_legend_handles_labels() self._check_colors(handles, linecolors=colors) + @pytest.mark.slow def test_parallel_coordinates(self, iris): from matplotlib import cm diff --git a/pandas/tests/plotting/test_series.py b/pandas/tests/plotting/test_series.py index 457ccc2ffce51..d0ed5cb754c40 100644 --- a/pandas/tests/plotting/test_series.py +++ b/pandas/tests/plotting/test_series.py @@ -1,6 +1,4 @@ """ Test cases for Series.plot """ - - from datetime import datetime from itertools import chain @@ -23,8 +21,6 @@ import pandas.plotting as plotting -pytestmark = pytest.mark.slow - @pytest.fixture def ts(): @@ -43,6 +39,7 @@ def iseries(): @td.skip_if_no_mpl class TestSeriesPlots(TestPlotBase): + @pytest.mark.slow def test_plot(self, ts): _check_plot_works(ts.plot, label="foo") _check_plot_works(ts.plot, use_index=False) @@ -64,7 +61,17 @@ def test_plot(self, ts): def test_plot_iseries(self, iseries): _check_plot_works(iseries.plot) - @pytest.mark.parametrize("kind", ["line", "bar", "barh", "kde", "hist", "box"]) + @pytest.mark.parametrize( + "kind", + [ + "line", + "bar", + "barh", + pytest.param("kde", marks=td.skip_if_no_scipy), + "hist", + "box", + ], + ) def test_plot_series_kinds(self, series, kind): _check_plot_works(series[:5].plot, kind=kind) @@ -495,6 +502,7 @@ def test_boxplot_series(self, ts): ylabels = ax.get_yticklabels() self._check_text_labels(ylabels, [""] * len(ylabels)) + @td.skip_if_no_scipy @pytest.mark.parametrize( "kind", plotting.PlotAccessor._common_kinds + plotting.PlotAccessor._series_kinds, @@ -516,6 +524,7 @@ def test_invalid_plot_data(self, kind): with pytest.raises(TypeError, match=msg): s.plot(kind=kind, ax=ax) + @td.skip_if_no_scipy @pytest.mark.parametrize("kind", plotting.PlotAccessor._common_kinds) def test_valid_object_plot(self, kind): s = Series(range(10), dtype=object) @@ -562,6 +571,7 @@ def test_errorbar_asymmetrical(self): tm.close() + @pytest.mark.slow def test_errorbar_plot(self): s = Series(np.arange(10), name="x") @@ -603,10 +613,13 @@ def test_errorbar_plot(self): with tm.external_error_raised(TypeError): s.plot(yerr=s_err) + @pytest.mark.slow def test_table(self, series): _check_plot_works(series.plot, table=True) _check_plot_works(series.plot, table=series) + @pytest.mark.slow + @td.skip_if_no_scipy def test_series_grid_settings(self): # Make sure plot defaults to rcParams['axes.grid'] setting, GH 9792 self._check_grid_settings( diff --git a/pandas/tests/plotting/test_style.py b/pandas/tests/plotting/test_style.py index 3c48eeaccbf34..665bda15724fd 100644 --- a/pandas/tests/plotting/test_style.py +++ b/pandas/tests/plotting/test_style.py @@ -5,8 +5,6 @@ pytest.importorskip("matplotlib") from pandas.plotting._matplotlib.style import get_standard_colors -pytestmark = pytest.mark.slow - class TestGetStandardColors: @pytest.mark.parametrize(