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

Use _gather internal for sort_* #9668

Merged
merged 4 commits into from
Nov 12, 2021
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
28 changes: 22 additions & 6 deletions python/cudf/cudf/core/indexed_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,10 +398,15 @@ def sort_index(
inds = idx._get_sorted_inds(
ascending=ascending, na_position=na_position
)
# TODO: This line is abusing the fact that take accepts a
# column, not just user-facing objects. We will want to
# refactor that in the future.
out = self.take(inds)
out = self._gather(inds)
# TODO: frame factory function should handle multilevel column
# names
if isinstance(
self, cudf.core.dataframe.DataFrame
) and isinstance(
self.columns, pd.core.indexes.multi.MultiIndex
):
out.columns = self.columns
elif (ascending and idx.is_monotonic_increasing) or (
not ascending and idx.is_monotonic_decreasing
):
Expand All @@ -410,7 +415,13 @@ def sort_index(
inds = idx.argsort(
ascending=ascending, na_position=na_position
)
out = self.take(inds)
out = self._gather(inds)
if isinstance(
self, cudf.core.dataframe.DataFrame
) and isinstance(
self.columns, pd.core.indexes.multi.MultiIndex
):
out.columns = self.columns
vyasr marked this conversation as resolved.
Show resolved Hide resolved
else:
labels = sorted(self._data.names, reverse=not ascending)
out = self[labels]
Expand Down Expand Up @@ -487,12 +498,17 @@ def sort_values(
return self

# argsort the `by` column
return self.take(
out = self._gather(
self._get_columns_by_label(by)._get_sorted_inds(
ascending=ascending, na_position=na_position
),
keep_index=not ignore_index,
)
if isinstance(self, cudf.core.dataframe.DataFrame) and isinstance(
self.columns, pd.core.indexes.multi.MultiIndex
):
out.columns = self.columns
return out

def _n_largest_or_smallest(self, largest, n, columns, keep):
# Get column to operate on
Expand Down