@@ -454,3 +454,76 @@ def test_fontsize(self):
454
454
self ._check_ticks_props (
455
455
df .boxplot ("a" , by = "b" , fontsize = 16 ), xlabelsize = 16 , ylabelsize = 16
456
456
)
457
+
458
+ @pytest .mark .parametrize (
459
+ "col, expected_xticklabel" ,
460
+ [
461
+ ("v" , ["(a, v)" , "(b, v)" , "(c, v)" , "(d, v)" , "(e, v)" ]),
462
+ (["v" ], ["(a, v)" , "(b, v)" , "(c, v)" , "(d, v)" , "(e, v)" ]),
463
+ ("v1" , ["(a, v1)" , "(b, v1)" , "(c, v1)" , "(d, v1)" , "(e, v1)" ]),
464
+ (
465
+ ["v" , "v1" ],
466
+ [
467
+ "(a, v)" ,
468
+ "(a, v1)" ,
469
+ "(b, v)" ,
470
+ "(b, v1)" ,
471
+ "(c, v)" ,
472
+ "(c, v1)" ,
473
+ "(d, v)" ,
474
+ "(d, v1)" ,
475
+ "(e, v)" ,
476
+ "(e, v1)" ,
477
+ ],
478
+ ),
479
+ (
480
+ None ,
481
+ [
482
+ "(a, v)" ,
483
+ "(a, v1)" ,
484
+ "(b, v)" ,
485
+ "(b, v1)" ,
486
+ "(c, v)" ,
487
+ "(c, v1)" ,
488
+ "(d, v)" ,
489
+ "(d, v1)" ,
490
+ "(e, v)" ,
491
+ "(e, v1)" ,
492
+ ],
493
+ ),
494
+ ],
495
+ )
496
+ def test_groupby_boxplot_subplots_false (self , col , expected_xticklabel ):
497
+ # GH 16748
498
+ df = DataFrame (
499
+ {
500
+ "cat" : np .random .choice (list ("abcde" ), 100 ),
501
+ "v" : np .random .rand (100 ),
502
+ "v1" : np .random .rand (100 ),
503
+ }
504
+ )
505
+ grouped = df .groupby ("cat" )
506
+
507
+ axes = _check_plot_works (
508
+ grouped .boxplot , subplots = False , column = col , return_type = "axes"
509
+ )
510
+
511
+ result_xticklabel = [x .get_text () for x in axes .get_xticklabels ()]
512
+ assert expected_xticklabel == result_xticklabel
513
+
514
+ def test_boxplot_multiindex_column (self ):
515
+ # GH 16748
516
+ arrays = [
517
+ ["bar" , "bar" , "baz" , "baz" , "foo" , "foo" , "qux" , "qux" ],
518
+ ["one" , "two" , "one" , "two" , "one" , "two" , "one" , "two" ],
519
+ ]
520
+ tuples = list (zip (* arrays ))
521
+ index = MultiIndex .from_tuples (tuples , names = ["first" , "second" ])
522
+ df = DataFrame (np .random .randn (3 , 8 ), index = ["A" , "B" , "C" ], columns = index )
523
+
524
+ col = [("bar" , "one" ), ("bar" , "two" )]
525
+ axes = _check_plot_works (df .boxplot , column = col , return_type = "axes" )
526
+
527
+ expected_xticklabel = ["(bar, one)" , "(bar, two)" ]
528
+ result_xticklabel = [x .get_text () for x in axes .get_xticklabels ()]
529
+ assert expected_xticklabel == result_xticklabel
0 commit comments