Skip to content

Commit 1234d6e

Browse files
committed
TST: Address matplotlib 3.10 deprecation of vert=
1 parent 4454660 commit 1234d6e

File tree

2 files changed

+35
-16
lines changed

2 files changed

+35
-16
lines changed

pandas/tests/plotting/frame/test_frame.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,12 @@ def test_boxplot_vertical(self, hist_df):
10761076
labels = [pprint_thing(c) for c in numeric_cols]
10771077

10781078
# if horizontal, yticklabels are rotated
1079-
ax = df.plot.box(rot=50, fontsize=8, vert=False)
1079+
kwargs = (
1080+
{"vert": False}
1081+
if Version(mpl.__version__) < Version("3.10")
1082+
else {"orientation": "horizontal"}
1083+
)
1084+
ax = df.plot.box(rot=50, fontsize=8, **kwargs)
10801085
_check_ticks_props(ax, xrot=0, yrot=50, ylabelsize=8)
10811086
_check_text_labels(ax.get_yticklabels(), labels)
10821087
assert len(ax.lines) == 7 * len(numeric_cols)
@@ -1086,12 +1091,13 @@ def test_boxplot_vertical_subplots(self, hist_df):
10861091
df = hist_df
10871092
numeric_cols = df._get_numeric_data().columns
10881093
labels = [pprint_thing(c) for c in numeric_cols]
1094+
kwargs = (
1095+
{"vert": False}
1096+
if Version(mpl.__version__) < Version("3.10")
1097+
else {"orientation": "horizontal"}
1098+
)
10891099
axes = _check_plot_works(
1090-
df.plot.box,
1091-
default_axes=True,
1092-
subplots=True,
1093-
vert=False,
1094-
logx=True,
1100+
df.plot.box, default_axes=True, subplots=True, logx=True, **kwargs
10951101
)
10961102
_check_axes_shape(axes, axes_num=3, layout=(1, 3))
10971103
_check_ax_scales(axes, xaxis="log")
@@ -1104,7 +1110,12 @@ def test_boxplot_vertical_positions(self, hist_df):
11041110
numeric_cols = df._get_numeric_data().columns
11051111
labels = [pprint_thing(c) for c in numeric_cols]
11061112
positions = np.array([3, 2, 8])
1107-
ax = df.plot.box(positions=positions, vert=False)
1113+
kwargs = (
1114+
{"vert": False}
1115+
if Version(mpl.__version__) < Version("3.10")
1116+
else {"orientation": "horizontal"}
1117+
)
1118+
ax = df.plot.box(positions=positions, **kwargs)
11081119
_check_text_labels(ax.get_yticklabels(), labels)
11091120
tm.assert_numpy_array_equal(ax.yaxis.get_ticklocs(), positions)
11101121
assert len(ax.lines) == 7 * len(numeric_cols)

pandas/tests/plotting/test_boxplot_method.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
_check_ticks_props,
2323
_check_visible,
2424
)
25+
from pandas.util.version import Version
2526

2627
from pandas.io.formats.printing import pprint_thing
2728

@@ -35,6 +36,17 @@ def _check_ax_limits(col, ax):
3536
assert y_max >= col.max()
3637

3738

39+
if Version(mpl._version__) < Version("3.10"):
40+
verts = [{"vert": False}, {"vert": True}]
41+
else:
42+
verts = [{"orientation": "horizontal"}, {"orientation": "vertical"}]
43+
44+
45+
@pytest.fixture(params=verts)
46+
def vert(request):
47+
return request.param
48+
49+
3850
class TestDataFramePlots:
3951
def test_stacked_boxplot_set_axis(self):
4052
# GH2980
@@ -312,7 +324,6 @@ def test_specified_props_kwd(self, props, expected):
312324

313325
assert result[expected][0].get_color() == "C1"
314326

315-
@pytest.mark.parametrize("vert", [True, False])
316327
def test_plot_xlabel_ylabel(self, vert):
317328
df = DataFrame(
318329
{
@@ -322,11 +333,10 @@ def test_plot_xlabel_ylabel(self, vert):
322333
}
323334
)
324335
xlabel, ylabel = "x", "y"
325-
ax = df.plot(kind="box", vert=vert, xlabel=xlabel, ylabel=ylabel)
336+
ax = df.plot(kind="box", xlabel=xlabel, ylabel=ylabel, **vert)
326337
assert ax.get_xlabel() == xlabel
327338
assert ax.get_ylabel() == ylabel
328339

329-
@pytest.mark.parametrize("vert", [True, False])
330340
def test_plot_box(self, vert):
331341
# GH 54941
332342
rng = np.random.default_rng(2)
@@ -335,13 +345,12 @@ def test_plot_box(self, vert):
335345

336346
xlabel, ylabel = "x", "y"
337347
_, axs = plt.subplots(ncols=2, figsize=(10, 7), sharey=True)
338-
df1.plot.box(ax=axs[0], vert=vert, xlabel=xlabel, ylabel=ylabel)
339-
df2.plot.box(ax=axs[1], vert=vert, xlabel=xlabel, ylabel=ylabel)
348+
df1.plot.box(ax=axs[0], xlabel=xlabel, ylabel=ylabel, **vert)
349+
df2.plot.box(ax=axs[1], xlabel=xlabel, ylabel=ylabel, **vert)
340350
for ax in axs:
341351
assert ax.get_xlabel() == xlabel
342352
assert ax.get_ylabel() == ylabel
343353

344-
@pytest.mark.parametrize("vert", [True, False])
345354
def test_boxplot_xlabel_ylabel(self, vert):
346355
df = DataFrame(
347356
{
@@ -351,11 +360,10 @@ def test_boxplot_xlabel_ylabel(self, vert):
351360
}
352361
)
353362
xlabel, ylabel = "x", "y"
354-
ax = df.boxplot(vert=vert, xlabel=xlabel, ylabel=ylabel)
363+
ax = df.boxplot(xlabel=xlabel, ylabel=ylabel, **vert)
355364
assert ax.get_xlabel() == xlabel
356365
assert ax.get_ylabel() == ylabel
357366

358-
@pytest.mark.parametrize("vert", [True, False])
359367
def test_boxplot_group_xlabel_ylabel(self, vert):
360368
df = DataFrame(
361369
{
@@ -365,7 +373,7 @@ def test_boxplot_group_xlabel_ylabel(self, vert):
365373
}
366374
)
367375
xlabel, ylabel = "x", "y"
368-
ax = df.boxplot(by="group", vert=vert, xlabel=xlabel, ylabel=ylabel)
376+
ax = df.boxplot(by="group", xlabel=xlabel, ylabel=ylabel, **vert)
369377
for subplot in ax:
370378
assert subplot.get_xlabel() == xlabel
371379
assert subplot.get_ylabel() == ylabel

0 commit comments

Comments
 (0)