Skip to content

Commit d677786

Browse files
mroeschkepooja-subramaniam
authored andcommitted
TST/CLN: Remove unneeded warning filtering in plotting helper (pandas-dev#50880)
1 parent 06fb0b6 commit d677786

File tree

3 files changed

+13
-22
lines changed

3 files changed

+13
-22
lines changed

pandas/tests/plotting/common.py

+13-19
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
TYPE_CHECKING,
99
Sequence,
1010
)
11-
import warnings
1211

1312
import numpy as np
1413

@@ -516,17 +515,14 @@ def get_y_axis(self, ax):
516515
return ax._shared_axes["y"]
517516

518517

519-
def _check_plot_works(f, filterwarnings="always", default_axes=False, **kwargs):
518+
def _check_plot_works(f, default_axes=False, **kwargs):
520519
"""
521520
Create plot and ensure that plot return object is valid.
522521
523522
Parameters
524523
----------
525524
f : func
526525
Plotting function.
527-
filterwarnings : str
528-
Warnings filter.
529-
See https://docs.python.org/3/library/warnings.html#warning-filter
530526
default_axes : bool, optional
531527
If False (default):
532528
- 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):
554550
gen_plots = _gen_two_subplots
555551

556552
ret = None
557-
with warnings.catch_warnings():
558-
warnings.simplefilter(filterwarnings)
559-
try:
560-
fig = kwargs.get("figure", plt.gcf())
561-
plt.clf()
553+
try:
554+
fig = kwargs.get("figure", plt.gcf())
555+
plt.clf()
562556

563-
for ret in gen_plots(f, fig, **kwargs):
564-
tm.assert_is_valid_plot_return_object(ret)
557+
for ret in gen_plots(f, fig, **kwargs):
558+
tm.assert_is_valid_plot_return_object(ret)
565559

566-
with tm.ensure_clean(return_filelike=True) as path:
567-
plt.savefig(path)
560+
with tm.ensure_clean(return_filelike=True) as path:
561+
plt.savefig(path)
568562

569-
except Exception as err:
570-
raise err
571-
finally:
572-
tm.close(fig)
563+
except Exception as err:
564+
raise err
565+
finally:
566+
tm.close(fig)
573567

574-
return ret
568+
return ret
575569

576570

577571
def _gen_default_plot(f, fig, **kwargs):

pandas/tests/plotting/test_hist_method.py

-1
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,6 @@ def test_hist_subplot_xrot(self):
413413
axes = _check_plot_works(
414414
df.hist,
415415
default_axes=True,
416-
filterwarnings="always",
417416
column="length",
418417
by="animal",
419418
bins=5,

pandas/tests/plotting/test_misc.py

-2
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ def test_scatter_matrix_axis(self, pass_axis):
109109
with tm.assert_produces_warning(UserWarning, check_stacklevel=False):
110110
axes = _check_plot_works(
111111
scatter_matrix,
112-
filterwarnings="always",
113112
frame=df,
114113
range_padding=0.1,
115114
ax=ax,
@@ -127,7 +126,6 @@ def test_scatter_matrix_axis(self, pass_axis):
127126
with tm.assert_produces_warning(UserWarning, check_stacklevel=False):
128127
axes = _check_plot_works(
129128
scatter_matrix,
130-
filterwarnings="always",
131129
frame=df,
132130
range_padding=0.1,
133131
ax=ax,

0 commit comments

Comments
 (0)