Skip to content

Commit daf999f

Browse files
authored
TST: use default_axes=True where multiple plots (#37734)
1 parent ce719fd commit daf999f

File tree

1 file changed

+63
-42
lines changed

1 file changed

+63
-42
lines changed

pandas/tests/plotting/test_frame.py

+63-42
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,25 @@ def test_plot(self):
5353

5454
df = self.tdf
5555
_check_plot_works(df.plot, grid=False)
56-
# _check_plot_works adds an ax so catch warning. see GH #13188
57-
with tm.assert_produces_warning(UserWarning):
58-
axes = _check_plot_works(df.plot, subplots=True)
56+
57+
# _check_plot_works adds an ax so use default_axes=True to avoid warning
58+
axes = _check_plot_works(df.plot, default_axes=True, subplots=True)
5959
self._check_axes_shape(axes, axes_num=4, layout=(4, 1))
6060

61-
with tm.assert_produces_warning(UserWarning):
62-
axes = _check_plot_works(df.plot, subplots=True, layout=(-1, 2))
61+
axes = _check_plot_works(
62+
df.plot,
63+
default_axes=True,
64+
subplots=True,
65+
layout=(-1, 2),
66+
)
6367
self._check_axes_shape(axes, axes_num=4, layout=(2, 2))
6468

65-
with tm.assert_produces_warning(UserWarning):
66-
axes = _check_plot_works(df.plot, subplots=True, use_index=False)
69+
axes = _check_plot_works(
70+
df.plot,
71+
default_axes=True,
72+
subplots=True,
73+
use_index=False,
74+
)
6775
self._check_ticks_props(axes, xrot=0)
6876
self._check_axes_shape(axes, axes_num=4, layout=(4, 1))
6977

@@ -84,8 +92,7 @@ def test_plot(self):
8492
_check_plot_works(df.plot, xticks=[1, 5, 10])
8593
_check_plot_works(df.plot, ylim=(-100, 100), xlim=(-100, 100))
8694

87-
with tm.assert_produces_warning(UserWarning):
88-
_check_plot_works(df.plot, subplots=True, title="blah")
95+
_check_plot_works(df.plot, default_axes=True, subplots=True, title="blah")
8996

9097
# We have to redo it here because _check_plot_works does two plots,
9198
# once without an ax kwarg and once with an ax kwarg and the new sharex
@@ -1405,9 +1412,7 @@ def test_plot_bar(self):
14051412

14061413
_check_plot_works(df.plot.bar)
14071414
_check_plot_works(df.plot.bar, legend=False)
1408-
# _check_plot_works adds an ax so catch warning. see GH #13188
1409-
with tm.assert_produces_warning(UserWarning):
1410-
_check_plot_works(df.plot.bar, subplots=True)
1415+
_check_plot_works(df.plot.bar, default_axes=True, subplots=True)
14111416
_check_plot_works(df.plot.bar, stacked=True)
14121417

14131418
df = DataFrame(
@@ -1629,9 +1634,13 @@ def test_boxplot_vertical(self):
16291634
self._check_text_labels(ax.get_yticklabels(), labels)
16301635
assert len(ax.lines) == self.bp_n_objects * len(numeric_cols)
16311636

1632-
# _check_plot_works adds an ax so catch warning. see GH #13188
1633-
with tm.assert_produces_warning(UserWarning):
1634-
axes = _check_plot_works(df.plot.box, subplots=True, vert=False, logx=True)
1637+
axes = _check_plot_works(
1638+
df.plot.box,
1639+
default_axes=True,
1640+
subplots=True,
1641+
vert=False,
1642+
logx=True,
1643+
)
16351644
self._check_axes_shape(axes, axes_num=3, layout=(1, 3))
16361645
self._check_ax_scales(axes, xaxis="log")
16371646
for ax, label in zip(axes, labels):
@@ -1698,8 +1707,12 @@ def test_kde_df(self):
16981707
ax = df.plot(kind="kde", rot=20, fontsize=5)
16991708
self._check_ticks_props(ax, xrot=20, xlabelsize=5, ylabelsize=5)
17001709

1701-
with tm.assert_produces_warning(UserWarning):
1702-
axes = _check_plot_works(df.plot, kind="kde", subplots=True)
1710+
axes = _check_plot_works(
1711+
df.plot,
1712+
default_axes=True,
1713+
kind="kde",
1714+
subplots=True,
1715+
)
17031716
self._check_axes_shape(axes, axes_num=4, layout=(4, 1))
17041717

17051718
axes = df.plot(kind="kde", logy=True, subplots=True)
@@ -1723,8 +1736,12 @@ def test_hist_df(self):
17231736
expected = [pprint_thing(c) for c in df.columns]
17241737
self._check_legend_labels(ax, labels=expected)
17251738

1726-
with tm.assert_produces_warning(UserWarning):
1727-
axes = _check_plot_works(df.plot.hist, subplots=True, logy=True)
1739+
axes = _check_plot_works(
1740+
df.plot.hist,
1741+
default_axes=True,
1742+
subplots=True,
1743+
logy=True,
1744+
)
17281745
self._check_axes_shape(axes, axes_num=4, layout=(4, 1))
17291746
self._check_ax_scales(axes, yaxis="log")
17301747

@@ -2624,9 +2641,11 @@ def test_pie_df(self):
26242641
ax = _check_plot_works(df.plot.pie, y=2)
26252642
self._check_text_labels(ax.texts, df.index)
26262643

2627-
# _check_plot_works adds an ax so catch warning. see GH #13188
2628-
with tm.assert_produces_warning(UserWarning):
2629-
axes = _check_plot_works(df.plot.pie, subplots=True)
2644+
axes = _check_plot_works(
2645+
df.plot.pie,
2646+
default_axes=True,
2647+
subplots=True,
2648+
)
26302649
assert len(axes) == len(df.columns)
26312650
for ax in axes:
26322651
self._check_text_labels(ax.texts, df.index)
@@ -2635,10 +2654,13 @@ def test_pie_df(self):
26352654

26362655
labels = ["A", "B", "C", "D", "E"]
26372656
color_args = ["r", "g", "b", "c", "m"]
2638-
with tm.assert_produces_warning(UserWarning):
2639-
axes = _check_plot_works(
2640-
df.plot.pie, subplots=True, labels=labels, colors=color_args
2641-
)
2657+
axes = _check_plot_works(
2658+
df.plot.pie,
2659+
default_axes=True,
2660+
subplots=True,
2661+
labels=labels,
2662+
colors=color_args,
2663+
)
26422664
assert len(axes) == len(df.columns)
26432665

26442666
for ax in axes:
@@ -2745,16 +2767,15 @@ def test_errorbar_plot_different_kinds(self, kind):
27452767
ax = _check_plot_works(df.plot, xerr=0.2, yerr=0.2, kind=kind)
27462768
self._check_has_errorbars(ax, xerr=2, yerr=2)
27472769

2748-
msg = (
2749-
"To output multiple subplots, "
2750-
"the figure containing the passed axes is being cleared"
2770+
axes = _check_plot_works(
2771+
df.plot,
2772+
default_axes=True,
2773+
yerr=df_err,
2774+
xerr=df_err,
2775+
subplots=True,
2776+
kind=kind,
27512777
)
2752-
with tm.assert_produces_warning(UserWarning, match=msg):
2753-
# Similar warnings were observed in GH #13188
2754-
axes = _check_plot_works(
2755-
df.plot, yerr=df_err, xerr=df_err, subplots=True, kind=kind
2756-
)
2757-
self._check_has_errorbars(axes, xerr=1, yerr=1)
2778+
self._check_has_errorbars(axes, xerr=1, yerr=1)
27582779

27592780
@pytest.mark.xfail(reason="Iterator is consumed", raises=ValueError)
27602781
@pytest.mark.slow
@@ -2826,14 +2847,14 @@ def test_errorbar_timeseries(self, kind):
28262847
ax = _check_plot_works(tdf.plot, yerr=tdf_err, kind=kind)
28272848
self._check_has_errorbars(ax, xerr=0, yerr=2)
28282849

2829-
msg = (
2830-
"To output multiple subplots, "
2831-
"the figure containing the passed axes is being cleared"
2850+
axes = _check_plot_works(
2851+
tdf.plot,
2852+
default_axes=True,
2853+
kind=kind,
2854+
yerr=tdf_err,
2855+
subplots=True,
28322856
)
2833-
with tm.assert_produces_warning(UserWarning, match=msg):
2834-
# Similar warnings were observed in GH #13188
2835-
axes = _check_plot_works(tdf.plot, kind=kind, yerr=tdf_err, subplots=True)
2836-
self._check_has_errorbars(axes, xerr=0, yerr=1)
2857+
self._check_has_errorbars(axes, xerr=0, yerr=1)
28372858

28382859
def test_errorbar_asymmetrical(self):
28392860
np.random.seed(0)

0 commit comments

Comments
 (0)