1
1
"""Test cases for .boxplot method"""
2
2
3
+ from __future__ import annotations
4
+
3
5
import itertools
4
6
import string
5
7
22
24
_check_ticks_props ,
23
25
_check_visible ,
24
26
)
27
+ from pandas .util .version import Version
25
28
26
29
from pandas .io .formats .printing import pprint_thing
27
30
@@ -35,6 +38,17 @@ def _check_ax_limits(col, ax):
35
38
assert y_max >= col .max ()
36
39
37
40
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
+
38
52
class TestDataFramePlots :
39
53
def test_stacked_boxplot_set_axis (self ):
40
54
# GH2980
@@ -312,7 +326,7 @@ def test_specified_props_kwd(self, props, expected):
312
326
313
327
assert result [expected ][0 ].get_color () == "C1"
314
328
315
- @pytest .mark .parametrize ( "vert" , [ True , False ] )
329
+ @pytest .mark .filterwarnings ( "ignore:set_ticklabels:UserWarning" )
316
330
def test_plot_xlabel_ylabel (self , vert ):
317
331
df = DataFrame (
318
332
{
@@ -322,11 +336,11 @@ def test_plot_xlabel_ylabel(self, vert):
322
336
}
323
337
)
324
338
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 )
326
340
assert ax .get_xlabel () == xlabel
327
341
assert ax .get_ylabel () == ylabel
328
342
329
- @pytest .mark .parametrize ( "vert" , [ True , False ] )
343
+ @pytest .mark .filterwarnings ( "ignore:set_ticklabels:UserWarning" )
330
344
def test_plot_box (self , vert ):
331
345
# GH 54941
332
346
rng = np .random .default_rng (2 )
@@ -335,13 +349,13 @@ def test_plot_box(self, vert):
335
349
336
350
xlabel , ylabel = "x" , "y"
337
351
_ , 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 )
340
354
for ax in axs :
341
355
assert ax .get_xlabel () == xlabel
342
356
assert ax .get_ylabel () == ylabel
343
357
344
- @pytest .mark .parametrize ( "vert" , [ True , False ] )
358
+ @pytest .mark .filterwarnings ( "ignore:set_ticklabels:UserWarning" )
345
359
def test_boxplot_xlabel_ylabel (self , vert ):
346
360
df = DataFrame (
347
361
{
@@ -351,11 +365,11 @@ def test_boxplot_xlabel_ylabel(self, vert):
351
365
}
352
366
)
353
367
xlabel , ylabel = "x" , "y"
354
- ax = df .boxplot (vert = vert , xlabel = xlabel , ylabel = ylabel )
368
+ ax = df .boxplot (xlabel = xlabel , ylabel = ylabel , ** vert )
355
369
assert ax .get_xlabel () == xlabel
356
370
assert ax .get_ylabel () == ylabel
357
371
358
- @pytest .mark .parametrize ( "vert" , [ True , False ] )
372
+ @pytest .mark .filterwarnings ( "ignore:set_ticklabels:UserWarning" )
359
373
def test_boxplot_group_xlabel_ylabel (self , vert ):
360
374
df = DataFrame (
361
375
{
@@ -365,23 +379,33 @@ def test_boxplot_group_xlabel_ylabel(self, vert):
365
379
}
366
380
)
367
381
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 )
369
383
for subplot in ax :
370
384
assert subplot .get_xlabel () == xlabel
371
385
assert subplot .get_ylabel () == ylabel
372
386
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
+ )
375
395
df = DataFrame (
376
396
{
377
397
"a" : np .random .default_rng (2 ).standard_normal (10 ),
378
398
"b" : np .random .default_rng (2 ).standard_normal (10 ),
379
399
"group" : np .random .default_rng (2 ).choice (["group1" , "group2" ], 10 ),
380
400
}
381
401
)
382
- ax = df .boxplot (by = "group" , vert = vert )
402
+ ax = df .boxplot (by = "group" , ** vert )
383
403
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
+ )
385
409
assert target_label == pprint_thing (["group" ])
386
410
387
411
0 commit comments