From 4f7f5a95af92dc441986bdc1814dc74fe0781d82 Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Sun, 6 Sep 2026 12:42:28 -0700 Subject: [PATCH 1/2] TEST: Focus MultiIndex sort_index coverage --- .../dataframe/methods/test_sort_index.py | 76 ++++++++++++++----- 1 file changed, 56 insertions(+), 20 deletions(-) diff --git a/python/cudf/cudf/tests/dataframe/methods/test_sort_index.py b/python/cudf/cudf/tests/dataframe/methods/test_sort_index.py index 4bb4c0d94ff0..bc05523c7b9d 100644 --- a/python/cudf/cudf/tests/dataframe/methods/test_sort_index.py +++ b/python/cudf/cudf/tests/dataframe/methods/test_sort_index.py @@ -67,26 +67,8 @@ def test_dataframe_sort_index( assert_eq(expected, got) -@pytest.mark.parametrize("axis", [0, 1, "index", "columns"]) -@pytest.mark.parametrize( - "level", - [ - 0, - "b", - 1, - ["b"], - "a", - ["a", "b"], - ["b", "a"], - [0, 1], - [1, 0], - [0, 2], - None, - ], -) -@pytest.mark.parametrize("na_position", ["first", "last"]) -def test_dataframe_mulitindex_sort_index( - request, axis, level, ascending, inplace, ignore_index, na_position +def _assert_dataframe_multiindex_sort_index( + axis, level, ascending, inplace, ignore_index, na_position ): pdf = pd.DataFrame( { @@ -122,6 +104,60 @@ def test_dataframe_mulitindex_sort_index( assert_eq(expected, got) +@pytest.mark.parametrize( + "level, ascending, na_position", + [ + (None, True, "last"), + (None, False, "last"), + (0, True, "first"), + (0, False, "last"), + ("b", False, "first"), + (1, True, "last"), + (1, False, "last"), + (["b"], False, "first"), + ("a", False, "last"), + (["a", "b"], True, "last"), + (["b", "a"], False, "last"), + ([0, 1], False, "last"), + ([1, 0], True, "last"), + ([0, 2], False, "first"), + ], +) +def test_dataframe_multiindex_sort_index(level, ascending, na_position): + _assert_dataframe_multiindex_sort_index( + axis=0, + level=level, + ascending=ascending, + inplace=False, + ignore_index=False, + na_position=na_position, + ) + + +@pytest.mark.parametrize("inplace", [True, False]) +@pytest.mark.parametrize("ignore_index", [True, False]) +def test_dataframe_multiindex_sort_index_lifecycle(inplace, ignore_index): + _assert_dataframe_multiindex_sort_index( + axis=0, + level=[1, 0], + ascending=False, + inplace=inplace, + ignore_index=ignore_index, + na_position="first", + ) + + +def test_dataframe_multiindex_sort_index_axis_alias(): + _assert_dataframe_multiindex_sort_index( + axis="index", + level=[0, 2], + ascending=False, + inplace=False, + ignore_index=False, + na_position="first", + ) + + def test_sort_index_axis_1_ignore_index_true_columnaccessor_state_names(): gdf = cudf.DataFrame([[1, 2, 3]], columns=["b", "a", "c"]) result = gdf.sort_index(axis=1, ignore_index=True) From e15d8d3899c58944e0e301512108304b90a1e5bc Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Tue, 8 Sep 2026 09:09:35 -0700 Subject: [PATCH 2/2] TEST: Assert inplace sort index return value --- python/cudf/cudf/tests/dataframe/methods/test_sort_index.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/python/cudf/cudf/tests/dataframe/methods/test_sort_index.py b/python/cudf/cudf/tests/dataframe/methods/test_sort_index.py index bc05523c7b9d..3e63abcf3373 100644 --- a/python/cudf/cudf/tests/dataframe/methods/test_sort_index.py +++ b/python/cudf/cudf/tests/dataframe/methods/test_sort_index.py @@ -99,6 +99,8 @@ def _assert_dataframe_multiindex_sort_index( ) if inplace is True: + assert expected is None + assert got is None assert_eq(pdf, gdf) else: assert_eq(expected, got)