16
16
import pytest
17
17
from typing_extensions import assert_type
18
18
19
- from tests import check
19
+ from tests import (
20
+ PD_LTE_22 ,
21
+ check ,
22
+ )
20
23
21
24
from pandas .plotting import (
22
25
deregister_matplotlib_converters ,
@@ -575,7 +578,10 @@ def test_plot_keywords(close_figures):
575
578
576
579
df = pd .DataFrame (np .random .rand (10 , 5 ), columns = ["A" , "B" , "C" , "D" , "E" ])
577
580
check (
578
- assert_type (df .plot (kind = "box" , vert = False , positions = [1 , 4 , 5 , 6 , 8 ]), Axes ),
581
+ assert_type (
582
+ df .plot (kind = "box" , orientation = "vertical" , positions = [1 , 4 , 5 , 6 , 8 ]),
583
+ Axes ,
584
+ ),
579
585
Axes ,
580
586
)
581
587
@@ -602,17 +608,67 @@ def test_grouped_dataframe_boxplot(close_figures):
602
608
check (assert_type (grouped .boxplot (), Series ), Series )
603
609
check (assert_type (grouped .boxplot (subplots = True ), Series ), Series )
604
610
611
+ # a single plot
612
+ if not PD_LTE_22 :
613
+ check (
614
+ assert_type (
615
+ grouped .boxplot (
616
+ subplots = False ,
617
+ rot = 45 ,
618
+ fontsize = 12 ,
619
+ figsize = (8 , 10 ),
620
+ orientation = "horizontal" ,
621
+ ),
622
+ Axes ,
623
+ ),
624
+ Axes ,
625
+ )
626
+
627
+
628
+ def test_grouped_dataframe_boxplot_single (close_figures ):
629
+ """
630
+ Test with pandas 2.2.3 separated to make it pass.
631
+
632
+ With pandas 2.2.3 the passing of certain keywords is broken so this test
633
+ is put separately to make sure that we have no Axes already created.
634
+ It will fail with `orientation="horizontal"`.
635
+ """
636
+ tuples = [t for t in itertools .product (range (10 ), range (2 ))]
637
+ index = pd .MultiIndex .from_tuples (tuples , names = ["lvl0" , "lvl1" ])
638
+ df = pd .DataFrame (
639
+ data = np .random .randn (len (index ), 2 ), columns = ["A" , "B" ], index = index
640
+ )
641
+ grouped = df .groupby (level = "lvl1" )
642
+
605
643
# a single plot
606
644
check (
607
645
assert_type (
608
646
grouped .boxplot (
609
- subplots = False , rot = 45 , fontsize = 12 , figsize = (8 , 10 ), vert = False
647
+ subplots = False ,
648
+ rot = 45 ,
649
+ fontsize = 12 ,
650
+ figsize = (8 , 10 ),
610
651
),
611
652
Axes ,
612
653
),
613
654
Axes ,
614
655
)
615
656
657
+ if not PD_LTE_22 :
658
+ check (
659
+ assert_type (
660
+ grouped .boxplot (
661
+ subplots = False ,
662
+ rot = 45 ,
663
+ fontsize = 12 ,
664
+ figsize = (8 , 10 ),
665
+ orientation = "horizontal" ,
666
+ ),
667
+ Axes ,
668
+ ),
669
+ Axes ,
670
+ )
671
+
616
672
# not a literal bool
617
673
check (assert_type (grouped .boxplot (subplots = bool (0.5 )), Union [Axes , Series ]), Series )
618
674
0 commit comments