diff --git a/pandas/tests/plotting/common.py b/pandas/tests/plotting/common.py index 20de38ebf6665..3cc0d59457528 100644 --- a/pandas/tests/plotting/common.py +++ b/pandas/tests/plotting/common.py @@ -8,7 +8,6 @@ TYPE_CHECKING, Sequence, ) -import warnings import numpy as np @@ -516,7 +515,7 @@ def get_y_axis(self, ax): return ax._shared_axes["y"] -def _check_plot_works(f, filterwarnings="always", default_axes=False, **kwargs): +def _check_plot_works(f, default_axes=False, **kwargs): """ Create plot and ensure that plot return object is valid. @@ -524,9 +523,6 @@ def _check_plot_works(f, filterwarnings="always", default_axes=False, **kwargs): ---------- f : func Plotting function. - filterwarnings : str - Warnings filter. - See https://docs.python.org/3/library/warnings.html#warning-filter default_axes : bool, optional If False (default): - If `ax` not in `kwargs`, then create subplot(211) and plot there @@ -554,24 +550,22 @@ def _check_plot_works(f, filterwarnings="always", default_axes=False, **kwargs): gen_plots = _gen_two_subplots ret = None - with warnings.catch_warnings(): - warnings.simplefilter(filterwarnings) - try: - fig = kwargs.get("figure", plt.gcf()) - plt.clf() + try: + fig = kwargs.get("figure", plt.gcf()) + plt.clf() - for ret in gen_plots(f, fig, **kwargs): - tm.assert_is_valid_plot_return_object(ret) + for ret in gen_plots(f, fig, **kwargs): + tm.assert_is_valid_plot_return_object(ret) - with tm.ensure_clean(return_filelike=True) as path: - plt.savefig(path) + with tm.ensure_clean(return_filelike=True) as path: + plt.savefig(path) - except Exception as err: - raise err - finally: - tm.close(fig) + except Exception as err: + raise err + finally: + tm.close(fig) - return ret + return ret def _gen_default_plot(f, fig, **kwargs): diff --git a/pandas/tests/plotting/test_hist_method.py b/pandas/tests/plotting/test_hist_method.py index 797aae7eaba3a..a80476038b7f1 100644 --- a/pandas/tests/plotting/test_hist_method.py +++ b/pandas/tests/plotting/test_hist_method.py @@ -413,7 +413,6 @@ def test_hist_subplot_xrot(self): axes = _check_plot_works( df.hist, default_axes=True, - filterwarnings="always", column="length", by="animal", bins=5, diff --git a/pandas/tests/plotting/test_misc.py b/pandas/tests/plotting/test_misc.py index 67486ec2a17b6..9f0753ce0fecd 100644 --- a/pandas/tests/plotting/test_misc.py +++ b/pandas/tests/plotting/test_misc.py @@ -109,7 +109,6 @@ def test_scatter_matrix_axis(self, pass_axis): with tm.assert_produces_warning(UserWarning, check_stacklevel=False): axes = _check_plot_works( scatter_matrix, - filterwarnings="always", frame=df, range_padding=0.1, ax=ax, @@ -127,7 +126,6 @@ def test_scatter_matrix_axis(self, pass_axis): with tm.assert_produces_warning(UserWarning, check_stacklevel=False): axes = _check_plot_works( scatter_matrix, - filterwarnings="always", frame=df, range_padding=0.1, ax=ax,