@@ -683,20 +683,25 @@ def test_bar_plt_xaxis_intervalrange(self):
683
683
)
684
684
685
685
686
- @pytest .fixture ( scope = "class" )
687
- def BSS_data ():
686
+ @pytest .fixture
687
+ def df_bar_data ():
688
688
return np .random .default_rng (3 ).integers (0 , 100 , 5 )
689
689
690
690
691
- @pytest .fixture (scope = "class" )
692
- def BSS_df (BSS_data ) -> DataFrame :
693
- BSS_df = DataFrame (
694
- {"A" : BSS_data , "B" : BSS_data [::- 1 ], "C" : BSS_data [0 ], "D" : BSS_data [- 1 ]}
691
+ @pytest .fixture
692
+ def df_bar_df (df_bar_data ) -> DataFrame :
693
+ df_bar_df = DataFrame (
694
+ {
695
+ "A" : df_bar_data ,
696
+ "B" : df_bar_data [::- 1 ],
697
+ "C" : df_bar_data [0 ],
698
+ "D" : df_bar_data [- 1 ],
699
+ }
695
700
)
696
- return BSS_df
701
+ return df_bar_df
697
702
698
703
699
- def _BSS_xyheight_from_ax_helper ( BSS_data , ax , subplot_division ):
704
+ def _df_bar_xyheight_from_ax_helper ( df_bar_data , ax , subplot_division ):
700
705
subplot_data_df_list = []
701
706
702
707
# get xy and height of squares representing data, separated by subplots
@@ -705,7 +710,7 @@ def _BSS_xyheight_from_ax_helper(BSS_data, ax, subplot_division):
705
710
[
706
711
(x .get_x (), x .get_y (), x .get_height ())
707
712
for x in ax [i ].findobj (plt .Rectangle )
708
- if x .get_height () in BSS_data
713
+ if x .get_height () in df_bar_data
709
714
]
710
715
)
711
716
subplot_data_df_list .append (
@@ -715,12 +720,14 @@ def _BSS_xyheight_from_ax_helper(BSS_data, ax, subplot_division):
715
720
return subplot_data_df_list
716
721
717
722
718
- def _BSS_subplot_checker ( BSS_data , BSS_df , subplot_data_df , subplot_columns ):
723
+ def _df_bar_subplot_checker ( df_bar_data , df_bar_df , subplot_data_df , subplot_columns ):
719
724
subplot_sliced_by_source = [
720
- subplot_data_df .iloc [len (BSS_data ) * i : len (BSS_data ) * (i + 1 )].reset_index ()
725
+ subplot_data_df .iloc [
726
+ len (df_bar_data ) * i : len (df_bar_data ) * (i + 1 )
727
+ ].reset_index ()
721
728
for i in range (len (subplot_columns ))
722
729
]
723
- expected_total_height = BSS_df .loc [:, subplot_columns ].sum (axis = 1 )
730
+ expected_total_height = df_bar_df .loc [:, subplot_columns ].sum (axis = 1 )
724
731
725
732
for i in range (len (subplot_columns )):
726
733
sliced_df = subplot_sliced_by_source [i ]
@@ -745,65 +752,67 @@ def _BSS_subplot_checker(BSS_data, BSS_df, subplot_data_df, subplot_columns):
745
752
)
746
753
747
754
748
- class TestBarSubplotStacked :
749
- # GH Issue 61018
750
- @pytest .mark .parametrize ("columns_used" , [["A" , "B" ], ["C" , "D" ], ["D" , "A" ]])
751
- def test_bar_1_subplot_1_double_stacked (self , BSS_data , BSS_df , columns_used ):
752
- BSS_df_trimmed = BSS_df [columns_used ]
753
- subplot_division = [columns_used ]
754
- ax = BSS_df_trimmed .plot (subplots = subplot_division , kind = "bar" , stacked = True )
755
- subplot_data_df_list = _BSS_xyheight_from_ax_helper (
756
- BSS_data , ax , subplot_division
755
+ # GH Issue 61018
756
+ @pytest .mark .parametrize ("columns_used" , [["A" , "B" ], ["C" , "D" ], ["D" , "A" ]])
757
+ def test_bar_1_subplot_1_double_stacked (df_bar_data , df_bar_df , columns_used ):
758
+ df_bar_df_trimmed = df_bar_df [columns_used ]
759
+ subplot_division = [columns_used ]
760
+ ax = df_bar_df_trimmed .plot (subplots = subplot_division , kind = "bar" , stacked = True )
761
+ subplot_data_df_list = _df_bar_xyheight_from_ax_helper (
762
+ df_bar_data , ax , subplot_division
763
+ )
764
+ for i in range (len (subplot_data_df_list )):
765
+ _df_bar_subplot_checker (
766
+ df_bar_data , df_bar_df_trimmed , subplot_data_df_list [i ], subplot_division [i ]
757
767
)
758
- for i in range (len (subplot_data_df_list )):
759
- _BSS_subplot_checker (
760
- BSS_data , BSS_df_trimmed , subplot_data_df_list [i ], subplot_division [i ]
761
- )
762
768
763
- @pytest .mark .parametrize (
764
- "columns_used" , [["A" , "B" , "C" ], ["A" , "C" , "B" ], ["D" , "A" , "C" ]]
769
+
770
+ @pytest .mark .parametrize (
771
+ "columns_used" , [["A" , "B" , "C" ], ["A" , "C" , "B" ], ["D" , "A" , "C" ]]
772
+ )
773
+ def test_bar_2_subplot_1_double_stacked (df_bar_data , df_bar_df , columns_used ):
774
+ df_bar_df_trimmed = df_bar_df [columns_used ]
775
+ subplot_division = [(columns_used [0 ], columns_used [1 ]), (columns_used [2 ],)]
776
+ ax = df_bar_df_trimmed .plot (subplots = subplot_division , kind = "bar" , stacked = True )
777
+ subplot_data_df_list = _df_bar_xyheight_from_ax_helper (
778
+ df_bar_data , ax , subplot_division
765
779
)
766
- def test_bar_2_subplot_1_double_stacked (self , BSS_data , BSS_df , columns_used ):
767
- BSS_df_trimmed = BSS_df [columns_used ]
768
- subplot_division = [(columns_used [0 ], columns_used [1 ]), (columns_used [2 ],)]
769
- ax = BSS_df_trimmed .plot (subplots = subplot_division , kind = "bar" , stacked = True )
770
- subplot_data_df_list = _BSS_xyheight_from_ax_helper (
771
- BSS_data , ax , subplot_division
772
- )
773
- for i in range (len (subplot_data_df_list )):
774
- _BSS_subplot_checker (
775
- BSS_data , BSS_df_trimmed , subplot_data_df_list [i ], subplot_division [i ]
776
- )
780
+ for i in range (len (subplot_data_df_list )):
781
+ _df_bar_subplot_checker (
782
+ df_bar_data , df_bar_df_trimmed , subplot_data_df_list [i ], subplot_division [i ]
783
+ )
777
784
778
- @pytest .mark .parametrize (
779
- "subplot_division" ,
780
- [
781
- [("A" , "B" ), ("C" , "D" )],
782
- [("A" , "D" ), ("C" , "B" )],
783
- [("B" , "C" ), ("D" , "A" )],
784
- [("B" , "D" ), ("C" , "A" )],
785
- ],
785
+
786
+ @pytest .mark .parametrize (
787
+ "subplot_division" ,
788
+ [
789
+ [("A" , "B" ), ("C" , "D" )],
790
+ [("A" , "D" ), ("C" , "B" )],
791
+ [("B" , "C" ), ("D" , "A" )],
792
+ [("B" , "D" ), ("C" , "A" )],
793
+ ],
794
+ )
795
+ def test_bar_2_subplot_2_double_stacked (df_bar_data , df_bar_df , subplot_division ):
796
+ ax = df_bar_df .plot (subplots = subplot_division , kind = "bar" , stacked = True )
797
+ subplot_data_df_list = _df_bar_xyheight_from_ax_helper (
798
+ df_bar_data , ax , subplot_division
786
799
)
787
- def test_bar_2_subplot_2_double_stacked (self , BSS_data , BSS_df , subplot_division ):
788
- ax = BSS_df .plot (subplots = subplot_division , kind = "bar" , stacked = True )
789
- subplot_data_df_list = _BSS_xyheight_from_ax_helper (
790
- BSS_data , ax , subplot_division
791
- )
792
- for i in range (len (subplot_data_df_list )):
793
- _BSS_subplot_checker (
794
- BSS_data , BSS_df , subplot_data_df_list [i ], subplot_division [i ]
795
- )
800
+ for i in range (len (subplot_data_df_list )):
801
+ _df_bar_subplot_checker (
802
+ df_bar_data , df_bar_df , subplot_data_df_list [i ], subplot_division [i ]
803
+ )
796
804
797
- @pytest .mark .parametrize (
798
- "subplot_division" ,
799
- [[("A" , "B" , "C" )], [("A" , "D" , "B" )], [("C" , "A" , "D" )], [("D" , "C" , "A" )]],
805
+
806
+ @pytest .mark .parametrize (
807
+ "subplot_division" ,
808
+ [[("A" , "B" , "C" )], [("A" , "D" , "B" )], [("C" , "A" , "D" )], [("D" , "C" , "A" )]],
809
+ )
810
+ def test_bar_2_subplots_1_triple_stacked (df_bar_data , df_bar_df , subplot_division ):
811
+ ax = df_bar_df .plot (subplots = subplot_division , kind = "bar" , stacked = True )
812
+ subplot_data_df_list = _df_bar_xyheight_from_ax_helper (
813
+ df_bar_data , ax , subplot_division
800
814
)
801
- def test_bar_2_subplots_1_triple_stacked (self , BSS_data , BSS_df , subplot_division ):
802
- ax = BSS_df .plot (subplots = subplot_division , kind = "bar" , stacked = True )
803
- subplot_data_df_list = _BSS_xyheight_from_ax_helper (
804
- BSS_data , ax , subplot_division
805
- )
806
- for i in range (len (subplot_data_df_list )):
807
- _BSS_subplot_checker (
808
- BSS_data , BSS_df , subplot_data_df_list [i ], subplot_division [i ]
809
- )
815
+ for i in range (len (subplot_data_df_list )):
816
+ _df_bar_subplot_checker (
817
+ df_bar_data , df_bar_df , subplot_data_df_list [i ], subplot_division [i ]
818
+ )
0 commit comments