Skip to content

TST/BUG: _gen_two_subplots always adding subplot even with passed axis #38646

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 2 commits into from
Dec 23, 2020
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: 2 additions & 1 deletion pandas/tests/plotting/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,8 @@ def _gen_two_subplots(f, fig, **kwargs):
"""
Create plot on two subplots forcefully created.
"""
kwargs.get("ax", fig.add_subplot(211))
if "ax" not in kwargs:
fig.add_subplot(211)
yield f(**kwargs)

if f is pd.plotting.bootstrap_plot:
Expand Down
18 changes: 17 additions & 1 deletion pandas/tests/plotting/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
import pandas.util._test_decorators as td

from pandas import DataFrame
from pandas.tests.plotting.common import TestPlotBase, _check_plot_works
from pandas.tests.plotting.common import (
TestPlotBase,
_check_plot_works,
_gen_two_subplots,
)

pytestmark = pytest.mark.slow

Expand All @@ -24,3 +28,15 @@ def test__check_ticks_props(self):
self._check_ticks_props(ax, yrot=0)
with pytest.raises(AssertionError, match=msg):
self._check_ticks_props(ax, ylabelsize=0)

def test__gen_two_subplots_with_ax(self):
fig = self.plt.gcf()
gen = _gen_two_subplots(f=lambda **kwargs: None, fig=fig, ax="test")
# On the first yield, no subplot should be added since ax was passed
next(gen)
assert fig.get_axes() == []
# On the second, the one axis should match fig.subplot(2, 1, 2)
next(gen)
axes = fig.get_axes()
assert len(axes) == 1
assert axes[0].get_geometry() == (2, 1, 2)