Skip to content

Commit 38f92dd

Browse files
mzeitlin11luckyvs1
authored andcommitted
TST/BUG: _gen_two_subplots (pandas-dev#38646)
1 parent 19dcd0f commit 38f92dd

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

pandas/tests/plotting/common.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,8 @@ def _gen_two_subplots(f, fig, **kwargs):
626626
"""
627627
Create plot on two subplots forcefully created.
628628
"""
629-
kwargs.get("ax", fig.add_subplot(211))
629+
if "ax" not in kwargs:
630+
fig.add_subplot(211)
630631
yield f(**kwargs)
631632

632633
if f is pd.plotting.bootstrap_plot:

pandas/tests/plotting/test_common.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
import pandas.util._test_decorators as td
44

55
from pandas import DataFrame
6-
from pandas.tests.plotting.common import TestPlotBase, _check_plot_works
6+
from pandas.tests.plotting.common import (
7+
TestPlotBase,
8+
_check_plot_works,
9+
_gen_two_subplots,
10+
)
711

812
pytestmark = pytest.mark.slow
913

@@ -24,3 +28,15 @@ def test__check_ticks_props(self):
2428
self._check_ticks_props(ax, yrot=0)
2529
with pytest.raises(AssertionError, match=msg):
2630
self._check_ticks_props(ax, ylabelsize=0)
31+
32+
def test__gen_two_subplots_with_ax(self):
33+
fig = self.plt.gcf()
34+
gen = _gen_two_subplots(f=lambda **kwargs: None, fig=fig, ax="test")
35+
# On the first yield, no subplot should be added since ax was passed
36+
next(gen)
37+
assert fig.get_axes() == []
38+
# On the second, the one axis should match fig.subplot(2, 1, 2)
39+
next(gen)
40+
axes = fig.get_axes()
41+
assert len(axes) == 1
42+
assert axes[0].get_geometry() == (2, 1, 2)

0 commit comments

Comments
 (0)