Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 58 additions & 20 deletions python/cudf/cudf/tests/dataframe/methods/test_sort_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand Down Expand Up @@ -117,11 +99,67 @@ def test_dataframe_mulitindex_sort_index(
)

if inplace is True:
assert expected is None
assert got is None
assert_eq(pdf, gdf)
else:
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):
Comment thread
coderabbitai[bot] marked this conversation as resolved.
_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():
Comment on lines +139 to +152

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idea: To further consolidate, could we expand the parameter inputs to test_dataframe_multiindex_sort_index so we can have 1 testing function that also captures these 2 extra tests?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, I'll do that in a follow-up PR.

_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)
Expand Down
Loading