Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DataFrame.sort_index to respect ignore_index on all axis #14995

Merged
merged 7 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 5 additions & 2 deletions python/cudf/cudf/core/indexed_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2608,12 +2608,15 @@ def sort_index(
and self._data.multiindex
):
out._set_column_names_like(self)
if ignore_index is True:
galipremsagar marked this conversation as resolved.
Show resolved Hide resolved
out = out.reset_index(drop=True)
else:
labels = sorted(self._data.names, reverse=not ascending)
out = self[labels]
if ignore_index is True:
galipremsagar marked this conversation as resolved.
Show resolved Hide resolved
out._data.rangeindex = True
out._data.names = list(range(0, len(self._data.names)))
galipremsagar marked this conversation as resolved.
Show resolved Hide resolved

if ignore_index is True:
out = out.reset_index(drop=True)
return self._mimic_inplace(out, inplace=inplace)

def memory_usage(self, index=True, deep=False):
Expand Down
13 changes: 12 additions & 1 deletion python/cudf/cudf/tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -3618,12 +3618,23 @@ def test_dataframe_mulitindex_sort_index(
):
request.applymarker(
pytest.mark.xfail(
condition=axis in (1, "columns")
condition=not PANDAS_GE_220
and axis in (1, "columns")
and ignore_index
and not (level is None and not ascending),
reason="https://github.com/pandas-dev/pandas/issues/56478",
)
)
request.applymarker(
pytest.mark.xfail(
condition=PANDAS_GE_220
and axis in (1, "columns")
and level is None
and not ascending
and ignore_index,
reason="https://github.com/pandas-dev/pandas/issues/57293",
)
)
pdf = pd.DataFrame(
{
"b": [1.0, 3.0, np.nan],
Expand Down
Loading