Skip to content

TST/CLN: Remove unneeded warning filtering in plotting helper #50880

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 13 additions & 19 deletions pandas/tests/plotting/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
TYPE_CHECKING,
Sequence,
)
import warnings

import numpy as np

Expand Down Expand Up @@ -516,17 +515,14 @@ 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.

Parameters
----------
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
Expand Down Expand Up @@ -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):
Expand Down
1 change: 0 additions & 1 deletion pandas/tests/plotting/test_hist_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions pandas/tests/plotting/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down