8000 FIX: fix cleanup warnings for errorbar timeseries by ivanovmg · Pull Request #36982 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

FIX: fix cleanup warnings for errorbar timeseries #36982

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
Changes from 1 commit
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
Prev Previous commit
Next Next commit
REF: refactor using assert_produces_warning
As agreed with charlesdong1991,
use assert_produces_warning
and leave a comment on which warning message is emitted
  • Loading branch information
ivanovmg committed Oct 9, 2020
commit 40833807cb783d9805dd073f8a88c6829423b012
38 changes: 10 additions & 28 deletions pandas/tests/plotting/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2792,35 +2792,17 @@ def test_errorbar_timeseries(self, kind):
ax = _check_plot_works(tdf.plot, yerr=tdf_err, kind=kind)
self._check_has_errorbars(ax, xerr=0, yerr=2)

# Do not use _check_plot_works as this function creates
# subplots inside, which led to uncaught warnings like this:
# UserWarning: To output multiple subplots,
# the figure containing the passed axes is being cleared
tdf.plot(kind=kind, yerr=tdf_err, subplots=True)
fig = plt.gcf()
axes = fig.get_axes()
for ax in axes:
self._check_has_errorbars(ax, xerr=0, yerr=1)

@pytest.mark.slow
@pytest.mark.parametrize("kind", ["line", "bar", "barh"])
def test_errorbar_plotting_twice_on_same_axis_warns(self, kind):
d = {"x": np.arange(12), "y": np.arange(12, 0, -1)}
d_err = {"x": np.ones(12) * 0.2, "y": np.ones(12) * 0.4}

ix = date_range("1/1/2000", "1/1/2001", freq="M")
tdf = DataFrame(d, index=ix)
tdf_err = DataFrame(d_err, index=ix)

with warnings.catch_warnings(record=True) as w:
# _check_plot_works creates subplots inside,
# thus the warning about overwriting must be raised
with tm.assert_produces_warning(UserWarning):
# _check_plot_works as this function creates
# subplots inside, which leads to warnings like this:
# UserWarning: To output multiple subplots,
# the figure containing the passed axes is being cleared
# Similar warnings were observed in GH #13188
axes = _check_plot_works(tdf.plot, kind=kind, yerr=tdf_err, subplots=True)
self._check_has_errorbars(axes, xerr=0, yerr=1)
assert len(w) == 1
assert issubclass(w[0].category, UserWarning)
msg = "the figure containing the passed axes is being cleared"
assert msg in str(w[0].message)
fig = plt.gcf()
axes = fig.get_axes()
for ax in axes:
self._check_has_errorbars(ax, xerr=0, yerr=1)

def test_errorbar_asymmetrical(self):

Expand Down
0