@@ -785,6 +785,48 @@ def test_sort_index_use_inf_as_na(self):
785
785
result = expected .sort_index ()
786
786
tm .assert_frame_equal (result , expected )
787
787
788
+ @pytest .mark .parametrize (
789
+ "ascending" ,
790
+ [(True , False ), [True , False ]],
791
+ )
792
+ def test_sort_index_ascending_tuple (self , ascending ):
793
+ df = DataFrame (
794
+ {
795
+ "legs" : [4 , 2 , 4 , 2 , 2 ],
796
+ },
797
+ index = MultiIndex .from_tuples (
798
+ [
799
+ ("mammal" , "dog" ),
800
+ ("bird" , "duck" ),
801
+ ("mammal" , "horse" ),
802
+ ("bird" , "penguin" ),
803
+ ("mammal" , "kangaroo" ),
804
+ ],
805
+ names = ["class" , "animal" ],
806
+ ),
807
+ )
808
+
809
+ # parameter `ascending`` is a tuple
810
+ result = df .sort_index (level = (0 , 1 ), ascending = ascending )
811
+
812
+ expected = DataFrame (
813
+ {
814
+ "legs" : [2 , 2 , 2 , 4 , 4 ],
815
+ },
816
+ index = MultiIndex .from_tuples (
817
+ [
818
+ ("bird" , "penguin" ),
819
+ ("bird" , "duck" ),
820
+ ("mammal" , "kangaroo" ),
821
+ ("mammal" , "horse" ),
822
+ ("mammal" , "dog" ),
823
+ ],
824
+ names = ["class" , "animal" ],
825
+ ),
826
+ )
827
+
828
+ tm .assert_frame_equal (result , expected )
829
+
788
830
789
831
class TestDataFrameSortIndexKey :
790
832
def test_sort_multi_index_key (self ):
0 commit comments