11""" Test cases for .boxplot method """
22
3+ from __future__ import annotations
4+
35import itertools
46import string
57
2224 _check_ticks_props ,
2325 _check_visible ,
2426)
27+ from pandas .util .version import Version
2528
2629from pandas .io .formats .printing import pprint_thing
2730
@@ -35,6 +38,17 @@ def _check_ax_limits(col, ax):
3538 assert y_max >= col .max ()
3639
3740
41+ if Version (mpl .__version__ ) < Version ("3.10" ):
42+ verts : list [dict [str , bool | str ]] = [{"vert" : False }, {"vert" : True }]
43+ else :
44+ verts = [{"orientation" : "horizontal" }, {"orientation" : "vertical" }]
45+
46+
47+ @pytest .fixture (params = verts )
48+ def vert (request ):
49+ return request .param
50+
51+
3852class TestDataFramePlots :
3953 def test_stacked_boxplot_set_axis (self ):
4054 # GH2980
@@ -315,7 +329,7 @@ def test_specified_props_kwd(self, props, expected):
315329
316330 assert result [expected ][0 ].get_color () == "C1"
317331
318- @pytest .mark .parametrize ( "vert" , [ True , False ] )
332+ @pytest .mark .filterwarnings ( "ignore:set_ticklabels:UserWarning" )
319333 def test_plot_xlabel_ylabel (self , vert ):
320334 df = DataFrame (
321335 {
@@ -325,11 +339,11 @@ def test_plot_xlabel_ylabel(self, vert):
325339 }
326340 )
327341 xlabel , ylabel = "x" , "y"
328- ax = df .plot (kind = "box" , vert = vert , xlabel = xlabel , ylabel = ylabel )
342+ ax = df .plot (kind = "box" , xlabel = xlabel , ylabel = ylabel , ** vert )
329343 assert ax .get_xlabel () == xlabel
330344 assert ax .get_ylabel () == ylabel
331345
332- @pytest .mark .parametrize ( "vert" , [ True , False ] )
346+ @pytest .mark .filterwarnings ( "ignore:set_ticklabels:UserWarning" )
333347 def test_plot_box (self , vert ):
334348 # GH 54941
335349 rng = np .random .default_rng (2 )
@@ -338,14 +352,14 @@ def test_plot_box(self, vert):
338352
339353 xlabel , ylabel = "x" , "y"
340354 _ , axs = plt .subplots (ncols = 2 , figsize = (10 , 7 ), sharey = True )
341- df1 .plot .box (ax = axs [0 ], vert = vert , xlabel = xlabel , ylabel = ylabel )
342- df2 .plot .box (ax = axs [1 ], vert = vert , xlabel = xlabel , ylabel = ylabel )
355+ df1 .plot .box (ax = axs [0 ], xlabel = xlabel , ylabel = ylabel , ** vert )
356+ df2 .plot .box (ax = axs [1 ], xlabel = xlabel , ylabel = ylabel , ** vert )
343357 for ax in axs :
344358 assert ax .get_xlabel () == xlabel
345359 assert ax .get_ylabel () == ylabel
346360 mpl .pyplot .close ()
347361
348- @pytest .mark .parametrize ( "vert" , [ True , False ] )
362+ @pytest .mark .filterwarnings ( "ignore:set_ticklabels:UserWarning" )
349363 def test_boxplot_xlabel_ylabel (self , vert ):
350364 df = DataFrame (
351365 {
@@ -355,11 +369,11 @@ def test_boxplot_xlabel_ylabel(self, vert):
355369 }
356370 )
357371 xlabel , ylabel = "x" , "y"
358- ax = df .boxplot (vert = vert , xlabel = xlabel , ylabel = ylabel )
372+ ax = df .boxplot (xlabel = xlabel , ylabel = ylabel , ** vert )
359373 assert ax .get_xlabel () == xlabel
360374 assert ax .get_ylabel () == ylabel
361375
362- @pytest .mark .parametrize ( "vert" , [ True , False ] )
376+ @pytest .mark .filterwarnings ( "ignore:set_ticklabels:UserWarning" )
363377 def test_boxplot_group_xlabel_ylabel (self , vert ):
364378 df = DataFrame (
365379 {
@@ -369,24 +383,35 @@ def test_boxplot_group_xlabel_ylabel(self, vert):
369383 }
370384 )
371385 xlabel , ylabel = "x" , "y"
372- ax = df .boxplot (by = "group" , vert = vert , xlabel = xlabel , ylabel = ylabel )
386+ ax = df .boxplot (by = "group" , xlabel = xlabel , ylabel = ylabel , ** vert )
373387 for subplot in ax :
374388 assert subplot .get_xlabel () == xlabel
375389 assert subplot .get_ylabel () == ylabel
376390 mpl .pyplot .close ()
377391
378- @pytest .mark .parametrize ("vert" , [True , False ])
379- def test_boxplot_group_no_xlabel_ylabel (self , vert ):
392+ @pytest .mark .filterwarnings ("ignore:set_ticklabels:UserWarning" )
393+ def test_boxplot_group_no_xlabel_ylabel (self , vert , request ):
394+ if Version (mpl .__version__ ) >= Version ("3.10" ) and vert == {
395+ "orientation" : "horizontal"
396+ }:
397+ request .applymarker (
398+ pytest .mark .xfail (reason = f"{ vert } fails starting with matplotlib 3.10" )
399+ )
380400 df = DataFrame (
381401 {
382402 "a" : np .random .default_rng (2 ).standard_normal (10 ),
383403 "b" : np .random .default_rng (2 ).standard_normal (10 ),
384404 "group" : np .random .default_rng (2 ).choice (["group1" , "group2" ], 10 ),
385405 }
386406 )
387- ax = df .boxplot (by = "group" , vert = vert )
407+ ax = df .boxplot (by = "group" , ** vert )
388408 for subplot in ax :
389- target_label = subplot .get_xlabel () if vert else subplot .get_ylabel ()
409+ target_label = (
410+ subplot .get_xlabel ()
411+ if vert == {"vert" : True } # noqa: PLR1714
412+ or vert == {"orientation" : "vertical" }
413+ else subplot .get_ylabel ()
414+ )
390415 assert target_label == pprint_thing (["group" ])
391416 mpl .pyplot .close ()
392417
0 commit comments