diff --git a/pandas/tests/plotting/common.py b/pandas/tests/plotting/common.py index f0ba5f14d59c6..82d67d1db3510 100644 --- a/pandas/tests/plotting/common.py +++ b/pandas/tests/plotting/common.py @@ -12,6 +12,7 @@ from pandas.core.dtypes.api import is_list_like +import pandas as pd from pandas import DataFrame, Series import pandas.util.testing as tm from pandas.util.testing import assert_is_valid_plot_return_object, ensure_clean @@ -541,13 +542,13 @@ def _check_plot_works(f, filterwarnings="always", **kwargs): assert_is_valid_plot_return_object(ret) - try: - kwargs["ax"] = fig.add_subplot(212) - ret = f(**kwargs) - except Exception: - pass + if f is pd.plotting.bootstrap_plot: + assert "ax" not in kwargs else: - assert_is_valid_plot_return_object(ret) + kwargs["ax"] = fig.add_subplot(212) + + ret = f(**kwargs) + assert_is_valid_plot_return_object(ret) with ensure_clean(return_filelike=True) as path: plt.savefig(path) diff --git a/pandas/tests/plotting/test_frame.py b/pandas/tests/plotting/test_frame.py index 84badba271fce..fd66888fc30e4 100644 --- a/pandas/tests/plotting/test_frame.py +++ b/pandas/tests/plotting/test_frame.py @@ -3,6 +3,7 @@ """ Test cases for DataFrame.plot """ from datetime import date, datetime +import itertools import string import warnings @@ -2604,12 +2605,6 @@ def test_errorbar_plot(self): ax = _check_plot_works(df.plot, yerr=np.ones((2, 12)) * 0.4) self._check_has_errorbars(ax, xerr=0, yerr=2) - # yerr is iterator - import itertools - - ax = _check_plot_works(df.plot, yerr=itertools.repeat(0.1, len(df))) - self._check_has_errorbars(ax, xerr=0, yerr=2) - # yerr is column name for yerr in ["yerr", "誤差"]: s_df = df.copy() @@ -2626,6 +2621,17 @@ def test_errorbar_plot(self): with pytest.raises((ValueError, TypeError)): df.plot(yerr=df_err) + @pytest.mark.xfail(reason="Iterator is consumed", raises=ValueError) + @pytest.mark.slow + def test_errorbar_plot_iterator(self): + with warnings.catch_warnings(): + d = {"x": np.arange(12), "y": np.arange(12, 0, -1)} + df = DataFrame(d) + + # yerr is iterator + ax = _check_plot_works(df.plot, yerr=itertools.repeat(0.1, len(df))) + self._check_has_errorbars(ax, xerr=0, yerr=2) + @pytest.mark.slow def test_errorbar_with_integer_column_names(self): # test with integer column names