Skip to content

TST: Add dedicated test for plt.savefig #55876

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
Nov 9, 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
3 changes: 0 additions & 3 deletions pandas/tests/plotting/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,9 +535,6 @@ def _check_plot_works(f, default_axes=False, **kwargs):
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)

finally:
plt.close(fig)

Expand Down
3 changes: 0 additions & 3 deletions pandas/tests/plotting/test_datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -1645,9 +1645,6 @@ def _check_plot_works(f, freq=None, series=None, *args, **kwargs):
ret = f(*args, **kwargs)
assert ret is not None # TODO: do something more intelligent

with tm.ensure_clean(return_filelike=True) as path:
plt.savefig(path)

# GH18439, GH#24088, statsmodels#4772
with tm.ensure_clean(return_filelike=True) as path:
pickle.dump(fig, path)
Expand Down
28 changes: 28 additions & 0 deletions pandas/tests/plotting/test_misc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" Test cases for misc plot functions """
import os

import numpy as np
import pytest
Expand All @@ -10,7 +11,9 @@
Index,
Series,
Timestamp,
date_range,
interval_range,
period_range,
plotting,
)
import pandas._testing as tm
Expand All @@ -23,6 +26,7 @@
)

mpl = pytest.importorskip("matplotlib")
plt = pytest.importorskip("matplotlib.pyplot")
cm = pytest.importorskip("matplotlib.cm")


Expand Down Expand Up @@ -69,6 +73,30 @@ def test_get_accessor_args():
assert len(kwargs) == 24


@pytest.mark.parametrize("kind", plotting.PlotAccessor._all_kinds)
@pytest.mark.parametrize(
"data", [DataFrame(np.arange(15).reshape(5, 3)), Series(range(5))]
)
@pytest.mark.parametrize(
"index",
[
Index(range(5)),
date_range("2020-01-01", periods=5),
period_range("2020-01-01", periods=5),
],
)
def test_savefig(kind, data, index):
fig, ax = plt.subplots()
data.index = index
kwargs = {}
if kind in ["hexbin", "scatter", "pie"]:
if isinstance(data, Series):
pytest.skip(f"{kind} not supported with Series")
kwargs = {"x": 0, "y": 1}
data.plot(kind=kind, ax=ax, **kwargs)
fig.savefig(os.devnull)


class TestSeriesPlots:
def test_autocorrelation_plot(self):
from pandas.plotting import autocorrelation_plot
Expand Down