Skip to content

Commit

Permalink
TST: Don't mark all plotting tests as slow (pandas-dev#46003)
Browse files Browse the repository at this point in the history
  • Loading branch information
mroeschke authored Feb 27, 2022
1 parent 6466fc6 commit 63616a6
Show file tree
Hide file tree
Showing 19 changed files with 88 additions and 72 deletions.
4 changes: 0 additions & 4 deletions ci/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
19 changes: 13 additions & 6 deletions pandas/plotting/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 0 additions & 3 deletions pandas/tests/plotting/common.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 6 additions & 2 deletions pandas/tests/plotting/frame/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)}
Expand Down Expand Up @@ -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])
Expand Down
2 changes: 0 additions & 2 deletions pandas/tests/plotting/frame/test_frame_color.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
_check_plot_works,
)

pytestmark = pytest.mark.slow


@td.skip_if_no_mpl
class TestDataFrameColor(TestPlotBase):
Expand Down
2 changes: 0 additions & 2 deletions pandas/tests/plotting/frame/test_frame_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
25 changes: 17 additions & 8 deletions pandas/tests/plotting/frame/test_frame_legend.py
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -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"])
Expand Down Expand Up @@ -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
Expand Down
28 changes: 15 additions & 13 deletions pandas/tests/plotting/frame/test_frame_subplots.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]))

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/plotting/frame/test_hist_box_by.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
[
Expand Down
3 changes: 0 additions & 3 deletions pandas/tests/plotting/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
7 changes: 5 additions & 2 deletions pandas/tests/plotting/test_boxplot_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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),
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions pandas/tests/plotting/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
_gen_two_subplots,
)

pytestmark = pytest.mark.slow


@td.skip_if_no_mpl
class TestCommon(TestPlotBase):
Expand Down
3 changes: 0 additions & 3 deletions pandas/tests/plotting/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down
17 changes: 8 additions & 9 deletions pandas/tests/plotting/test_datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions pandas/tests/plotting/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 3 additions & 2 deletions pandas/tests/plotting/test_hist_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
_check_plot_works,
)

pytestmark = pytest.mark.slow


@pytest.fixture
def ts():
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand Down
Loading

0 comments on commit 63616a6

Please sign in to comment.