Skip to content

Commit 4083380

Browse files
committed
REF: refactor using assert_produces_warning
As agreed with charlesdong1991, use assert_produces_warning and leave a comment on which warning message is emitted
1 parent 1c04f3c commit 4083380

File tree

1 file changed

+10
-28
lines changed

1 file changed

+10
-28
lines changed

pandas/tests/plotting/test_frame.py

+10-28
Original file line numberDiff line numberDiff line change
@@ -2792,35 +2792,17 @@ def test_errorbar_timeseries(self, kind):
27922792
ax = _check_plot_works(tdf.plot, yerr=tdf_err, kind=kind)
27932793
self._check_has_errorbars(ax, xerr=0, yerr=2)
27942794

2795-
# Do not use _check_plot_works as this function creates
2796-
# subplots inside, which led to uncaught warnings like this:
2797-
# UserWarning: To output multiple subplots,
2798-
# the figure containing the passed axes is being cleared
2799-
tdf.plot(kind=kind, yerr=tdf_err, subplots=True)
2800-
fig = plt.gcf()
2801-
axes = fig.get_axes()
2802-
for ax in axes:
2803-
self._check_has_errorbars(ax, xerr=0, yerr=1)
2804-
2805-
@pytest.mark.slow
2806-
@pytest.mark.parametrize("kind", ["line", "bar", "barh"])
2807-
def test_errorbar_plotting_twice_on_same_axis_warns(self, kind):
2808-
d = {"x": np.arange(12), "y": np.arange(12, 0, -1)}
2809-
d_err = {"x": np.ones(12) * 0.2, "y": np.ones(12) * 0.4}
2810-
2811-
ix = date_range("1/1/2000", "1/1/2001", freq="M")
2812-
tdf = DataFrame(d, index=ix)
2813-
tdf_err = DataFrame(d_err, index=ix)
2814-
2815-
with warnings.catch_warnings(record=True) as w:
2816-
# _check_plot_works creates subplots inside,
2817-
# thus the warning about overwriting must be raised
2795+
with tm.assert_produces_warning(UserWarning):
2796+
# _check_plot_works as this function creates
2797+
# subplots inside, which leads to warnings like this:
2798+
# UserWarning: To output multiple subplots,
2799+
# the figure containing the passed axes is being cleared
2800+
# Similar warnings were observed in GH #13188
28182801
axes = _check_plot_works(tdf.plot, kind=kind, yerr=tdf_err, subplots=True)
2819-
self._check_has_errorbars(axes, xerr=0, yerr=1)
2820-
assert len(w) == 1
2821-
assert issubclass(w[0].category, UserWarning)
2822-
msg = "the figure containing the passed axes is being cleared"
2823-
assert msg in str(w[0].message)
2802+
fig = plt.gcf()
2803+
axes = fig.get_axes()
2804+
for ax in axes:
2805+
self._check_has_errorbars(ax, xerr=0, yerr=1)
28242806

28252807
def test_errorbar_asymmetrical(self):
28262808

0 commit comments

Comments
 (0)