Skip to content

Commit ecee969

Browse files
authored
Test that using a tuple or list for parameter ascending of sort_index is the same (#43963)
1 parent cc058e0 commit ecee969

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

pandas/tests/frame/methods/test_sort_index.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,48 @@ def test_sort_index_use_inf_as_na(self):
785785
result = expected.sort_index()
786786
tm.assert_frame_equal(result, expected)
787787

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+
788830

789831
class TestDataFrameSortIndexKey:
790832
def test_sort_multi_index_key(self):

0 commit comments

Comments
 (0)