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
@@ -312,7 +326,7 @@ def test_specified_props_kwd(self, props, expected):
312326
313327 assert result [expected ][0 ].get_color () == "C1"
314328
315- @pytest .mark .parametrize ( "vert" , [ True , False ] )
329+ @pytest .mark .filterwarnings ( "ignore:set_ticklabels:UserWarning" )
316330 def test_plot_xlabel_ylabel (self , vert ):
317331 df = DataFrame (
318332 {
@@ -322,11 +336,11 @@ def test_plot_xlabel_ylabel(self, vert):
322336 }
323337 )
324338 xlabel , ylabel = "x" , "y"
325- ax = df .plot (kind = "box" , vert = vert , xlabel = xlabel , ylabel = ylabel )
339+ ax = df .plot (kind = "box" , xlabel = xlabel , ylabel = ylabel , ** vert )
326340 assert ax .get_xlabel () == xlabel
327341 assert ax .get_ylabel () == ylabel
328342
329- @pytest .mark .parametrize ( "vert" , [ True , False ] )
343+ @pytest .mark .filterwarnings ( "ignore:set_ticklabels:UserWarning" )
330344 def test_plot_box (self , vert ):
331345 # GH 54941
332346 rng = np .random .default_rng (2 )
@@ -335,13 +349,13 @@ def test_plot_box(self, vert):
335349
336350 xlabel , ylabel = "x" , "y"
337351 _ , 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 )
352+ df1 .plot .box (ax = axs [0 ], xlabel = xlabel , ylabel = ylabel , ** vert )
353+ df2 .plot .box (ax = axs [1 ], xlabel = xlabel , ylabel = ylabel , ** vert )
340354 for ax in axs :
341355 assert ax .get_xlabel () == xlabel
342356 assert ax .get_ylabel () == ylabel
343357
344- @pytest .mark .parametrize ( "vert" , [ True , False ] )
358+ @pytest .mark .filterwarnings ( "ignore:set_ticklabels:UserWarning" )
345359 def test_boxplot_xlabel_ylabel (self , vert ):
346360 df = DataFrame (
347361 {
@@ -351,11 +365,11 @@ def test_boxplot_xlabel_ylabel(self, vert):
351365 }
352366 )
353367 xlabel , ylabel = "x" , "y"
354- ax = df .boxplot (vert = vert , xlabel = xlabel , ylabel = ylabel )
368+ ax = df .boxplot (xlabel = xlabel , ylabel = ylabel , ** vert )
355369 assert ax .get_xlabel () == xlabel
356370 assert ax .get_ylabel () == ylabel
357371
358- @pytest .mark .parametrize ( "vert" , [ True , False ] )
372+ @pytest .mark .filterwarnings ( "ignore:set_ticklabels:UserWarning" )
359373 def test_boxplot_group_xlabel_ylabel (self , vert ):
360374 df = DataFrame (
361375 {
@@ -365,23 +379,33 @@ def test_boxplot_group_xlabel_ylabel(self, vert):
365379 }
366380 )
367381 xlabel , ylabel = "x" , "y"
368- ax = df .boxplot (by = "group" , vert = vert , xlabel = xlabel , ylabel = ylabel )
382+ ax = df .boxplot (by = "group" , xlabel = xlabel , ylabel = ylabel , ** vert )
369383 for subplot in ax :
370384 assert subplot .get_xlabel () == xlabel
371385 assert subplot .get_ylabel () == ylabel
372386
373- @pytest .mark .parametrize ("vert" , [True , False ])
374- def test_boxplot_group_no_xlabel_ylabel (self , vert ):
387+ @pytest .mark .filterwarnings ("ignore:set_ticklabels:UserWarning" )
388+ def test_boxplot_group_no_xlabel_ylabel (self , vert , request ):
389+ if Version (mpl .__version__ ) >= Version ("3.10" ) and vert == {
390+ "orientation" : "horizontal"
391+ }:
392+ request .applymarker (
393+ pytest .mark .xfail (reason = f"{ vert } fails starting with matplotlib 3.10" )
394+ )
375395 df = DataFrame (
376396 {
377397 "a" : np .random .default_rng (2 ).standard_normal (10 ),
378398 "b" : np .random .default_rng (2 ).standard_normal (10 ),
379399 "group" : np .random .default_rng (2 ).choice (["group1" , "group2" ], 10 ),
380400 }
381401 )
382- ax = df .boxplot (by = "group" , vert = vert )
402+ ax = df .boxplot (by = "group" , ** vert )
383403 for subplot in ax :
384- target_label = subplot .get_xlabel () if vert else subplot .get_ylabel ()
404+ target_label = (
405+ subplot .get_xlabel ()
406+ if vert == {"vert" : True } or vert == {"orientation" : "vertical" }
407+ else subplot .get_ylabel ()
408+ )
385409 assert target_label == pprint_thing (["group" ])
386410
387411
0 commit comments