@@ -392,38 +392,51 @@ def test_grouped_box_return_type(self, hist_df):
392
392
result , None , expected_keys = ["height" , "weight" , "category" ]
393
393
)
394
394
395
+ @pytest .mark .slow
396
+ def test_grouped_box_return_type_groupby (self , hist_df ):
397
+ df = hist_df
395
398
# now for groupby
396
399
result = df .groupby ("gender" ).boxplot (return_type = "dict" )
397
400
_check_box_return_type (result , "dict" , expected_keys = ["Male" , "Female" ])
398
401
399
- columns2 = "X B C D A G Y N Q O" . split ()
400
- df2 = DataFrame ( np . random . randn ( 50 , 10 ), columns = columns2 )
401
- categories2 = "A B C D E F G H I J" . split ()
402
- df2 [ "category" ] = categories2 * 5
402
+ @ pytest . mark . slow
403
+ @ pytest . mark . parametrize ( "return_type" , [ "dict" , "axes" , "both" ] )
404
+ def test_grouped_box_return_type_arg ( self , hist_df , return_type ):
405
+ df = hist_df
403
406
404
- for t in ["dict" , "axes" , "both" ]:
405
- returned = df .groupby ("classroom" ).boxplot (return_type = t )
406
- _check_box_return_type (returned , t , expected_keys = ["A" , "B" , "C" ])
407
+ returned = df .groupby ("classroom" ).boxplot (return_type = return_type )
408
+ _check_box_return_type (returned , return_type , expected_keys = ["A" , "B" , "C" ])
407
409
408
- returned = df .boxplot (by = "classroom" , return_type = t )
409
- _check_box_return_type (
410
- returned , t , expected_keys = ["height" , "weight" , "category" ]
411
- )
410
+ returned = df .boxplot (by = "classroom" , return_type = return_type )
411
+ _check_box_return_type (
412
+ returned , return_type , expected_keys = ["height" , "weight" , "category" ]
413
+ )
412
414
413
- returned = df2 .groupby ("category" ).boxplot (return_type = t )
414
- _check_box_return_type (returned , t , expected_keys = categories2 )
415
+ @pytest .mark .slow
416
+ @pytest .mark .parametrize ("return_type" , ["dict" , "axes" , "both" ])
417
+ def test_grouped_box_return_type_arg_duplcate_cats (self , return_type ):
418
+ columns2 = "X B C D A" .split ()
419
+ df2 = DataFrame (np .random .randn (6 , 5 ), columns = columns2 )
420
+ categories2 = "A B" .split ()
421
+ df2 ["category" ] = categories2 * 3
422
+
423
+ returned = df2 .groupby ("category" ).boxplot (return_type = return_type )
424
+ _check_box_return_type (returned , return_type , expected_keys = categories2 )
415
425
416
- returned = df2 .boxplot (by = "category" , return_type = t )
417
- _check_box_return_type (returned , t , expected_keys = columns2 )
426
+ returned = df2 .boxplot (by = "category" , return_type = return_type )
427
+ _check_box_return_type (returned , return_type , expected_keys = columns2 )
418
428
419
429
@pytest .mark .slow
420
- def test_grouped_box_layout (self , hist_df ):
430
+ def test_grouped_box_layout_too_small (self , hist_df ):
421
431
df = hist_df
422
432
423
433
msg = "Layout of 1x1 must be larger than required size 2"
424
434
with pytest .raises (ValueError , match = msg ):
425
435
df .boxplot (column = ["weight" , "height" ], by = df .gender , layout = (1 , 1 ))
426
436
437
+ @pytest .mark .slow
438
+ def test_grouped_box_layout_needs_by (self , hist_df ):
439
+ df = hist_df
427
440
msg = "The 'layout' keyword is not supported when 'by' is None"
428
441
with pytest .raises (ValueError , match = msg ):
429
442
df .boxplot (
@@ -432,79 +445,84 @@ def test_grouped_box_layout(self, hist_df):
432
445
return_type = "dict" ,
433
446
)
434
447
448
+ @pytest .mark .slow
449
+ def test_grouped_box_layout_positive_layout (self , hist_df ):
450
+ df = hist_df
435
451
msg = "At least one dimension of layout must be positive"
436
452
with pytest .raises (ValueError , match = msg ):
437
453
df .boxplot (column = ["weight" , "height" ], by = df .gender , layout = (- 1 , - 1 ))
438
454
439
- # _check_plot_works adds an ax so catch warning. see GH #13188
440
- with tm .assert_produces_warning (UserWarning , check_stacklevel = False ):
441
- _check_plot_works (
442
- df .groupby ("gender" ).boxplot , column = "height" , return_type = "dict"
443
- )
444
- _check_axes_shape (mpl .pyplot .gcf ().axes , axes_num = 2 , layout = (1 , 2 ))
445
-
446
- with tm .assert_produces_warning (UserWarning , check_stacklevel = False ):
447
- _check_plot_works (
448
- df .groupby ("category" ).boxplot , column = "height" , return_type = "dict"
449
- )
450
- _check_axes_shape (mpl .pyplot .gcf ().axes , axes_num = 4 , layout = (2 , 2 ))
451
-
452
- # GH 6769
455
+ @pytest .mark .slow
456
+ @pytest .mark .parametrize (
457
+ "gb_key, axes_num, rows" ,
458
+ [["gender" , 2 , 1 ], ["category" , 4 , 2 ], ["classroom" , 3 , 2 ]],
459
+ )
460
+ def test_grouped_box_layout_positive_layout_axes (
461
+ self , hist_df , gb_key , axes_num , rows
462
+ ):
463
+ df = hist_df
464
+ # _check_plot_works adds an ax so catch warning. see GH #13188 GH 6769
453
465
with tm .assert_produces_warning (UserWarning , check_stacklevel = False ):
454
466
_check_plot_works (
455
- df .groupby ("classroom" ).boxplot , column = "height" , return_type = "dict"
467
+ df .groupby (gb_key ).boxplot , column = "height" , return_type = "dict"
456
468
)
457
- _check_axes_shape (mpl .pyplot .gcf ().axes , axes_num = 3 , layout = (2 , 2 ))
469
+ _check_axes_shape (mpl .pyplot .gcf ().axes , axes_num = axes_num , layout = (rows , 2 ))
458
470
471
+ @pytest .mark .slow
472
+ @pytest .mark .parametrize (
473
+ "col, visible" , [["height" , False ], ["weight" , True ], ["category" , True ]]
474
+ )
475
+ def test_grouped_box_layout_visible (self , hist_df , col , visible ):
476
+ df = hist_df
459
477
# GH 5897
460
478
axes = df .boxplot (
461
479
column = ["height" , "weight" , "category" ], by = "gender" , return_type = "axes"
462
480
)
463
481
_check_axes_shape (mpl .pyplot .gcf ().axes , axes_num = 3 , layout = (2 , 2 ))
464
- for ax in [axes ["height" ]]:
465
- _check_visible (ax .get_xticklabels (), visible = False )
466
- _check_visible ([ax .xaxis .get_label ()], visible = False )
467
- for ax in [axes ["weight" ], axes ["category" ]]:
468
- _check_visible (ax .get_xticklabels ())
469
- _check_visible ([ax .xaxis .get_label ()])
482
+ ax = axes [col ]
483
+ _check_visible (ax .get_xticklabels (), visible = visible )
484
+ _check_visible ([ax .xaxis .get_label ()], visible = visible )
470
485
486
+ @pytest .mark .slow
487
+ def test_grouped_box_layout_shape (self , hist_df ):
488
+ df = hist_df
471
489
df .groupby ("classroom" ).boxplot (
472
490
column = ["height" , "weight" , "category" ], return_type = "dict"
473
491
)
474
492
_check_axes_shape (mpl .pyplot .gcf ().axes , axes_num = 3 , layout = (2 , 2 ))
475
493
494
+ @pytest .mark .slow
495
+ @pytest .mark .parametrize ("cols" , [2 , - 1 ])
496
+ def test_grouped_box_layout_works (self , hist_df , cols ):
497
+ df = hist_df
476
498
with tm .assert_produces_warning (UserWarning , check_stacklevel = False ):
477
499
_check_plot_works (
478
500
df .groupby ("category" ).boxplot ,
479
501
column = "height" ,
480
- layout = (3 , 2 ),
481
- return_type = "dict" ,
482
- )
483
- _check_axes_shape (mpl .pyplot .gcf ().axes , axes_num = 4 , layout = (3 , 2 ))
484
- with tm .assert_produces_warning (UserWarning , check_stacklevel = False ):
485
- _check_plot_works (
486
- df .groupby ("category" ).boxplot ,
487
- column = "height" ,
488
- layout = (3 , - 1 ),
502
+ layout = (3 , cols ),
489
503
return_type = "dict" ,
490
504
)
491
505
_check_axes_shape (mpl .pyplot .gcf ().axes , axes_num = 4 , layout = (3 , 2 ))
492
506
493
- df .boxplot (column = ["height" , "weight" , "category" ], by = "gender" , layout = (4 , 1 ))
494
- _check_axes_shape (mpl .pyplot .gcf ().axes , axes_num = 3 , layout = (4 , 1 ))
495
-
496
- df .boxplot (column = ["height" , "weight" , "category" ], by = "gender" , layout = (- 1 , 1 ))
497
- _check_axes_shape (mpl .pyplot .gcf ().axes , axes_num = 3 , layout = (3 , 1 ))
498
-
499
- df .groupby ("classroom" ).boxplot (
500
- column = ["height" , "weight" , "category" ], layout = (1 , 4 ), return_type = "dict"
507
+ @pytest .mark .slow
508
+ @pytest .mark .parametrize ("rows, res" , [[4 , 4 ], [- 1 , 3 ]])
509
+ def test_grouped_box_layout_axes_shape_rows (self , hist_df , rows , res ):
510
+ df = hist_df
511
+ df .boxplot (
512
+ column = ["height" , "weight" , "category" ], by = "gender" , layout = (rows , 1 )
501
513
)
502
- _check_axes_shape (mpl .pyplot .gcf ().axes , axes_num = 3 , layout = (1 , 4 ))
514
+ _check_axes_shape (mpl .pyplot .gcf ().axes , axes_num = 3 , layout = (res , 1 ))
503
515
516
+ @pytest .mark .slow
517
+ @pytest .mark .parametrize ("cols, res" , [[4 , 4 ], [- 1 , 3 ]])
518
+ def test_grouped_box_layout_axes_shape_cols_groupby (self , hist_df , cols , res ):
519
+ df = hist_df
504
520
df .groupby ("classroom" ).boxplot (
505
- column = ["height" , "weight" , "category" ], layout = (1 , - 1 ), return_type = "dict"
521
+ column = ["height" , "weight" , "category" ],
522
+ layout = (1 , cols ),
523
+ return_type = "dict" ,
506
524
)
507
- _check_axes_shape (mpl .pyplot .gcf ().axes , axes_num = 3 , layout = (1 , 3 ))
525
+ _check_axes_shape (mpl .pyplot .gcf ().axes , axes_num = 3 , layout = (1 , res ))
508
526
509
527
@pytest .mark .slow
510
528
def test_grouped_box_multiple_axes (self , hist_df ):
0 commit comments