-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
ENH: Add ignore_index for df.sort_values and series.sort_values #30402
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
Changes from all commits
7e461a1
1314059
8bcb313
1f9a4ce
5f924c3
d0a134f
6d52765
a31797d
b80f380
b997d3f
12d1260
4ff2493
e9d63f4
70ffec7
b4245d7
f9e7ec2
d95a89f
f241e67
7f9846a
bbb4754
3c37eb9
4ce9f43
0f89aa2
d02b651
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2693,6 +2693,7 @@ def sort_values( | |
inplace=False, | ||
kind="quicksort", | ||
na_position="last", | ||
ignore_index=False, | ||
WillAyd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
): | ||
""" | ||
Sort by the values. | ||
|
@@ -2715,6 +2716,10 @@ def sort_values( | |
na_position : {'first' or 'last'}, default 'last' | ||
Argument 'first' puts NaNs at the beginning, 'last' puts NaNs at | ||
the end. | ||
ignore_index : bool, default False | ||
If True, the resulting axis will be labeled 0, 1, …, n - 1. | ||
|
||
.. versionadded:: 1.0.0 | ||
|
||
Returns | ||
------- | ||
|
@@ -2820,7 +2825,7 @@ def _try_kind_sort(arr): | |
return arr.argsort(kind="quicksort") | ||
|
||
arr = self._values | ||
sortedIdx = np.empty(len(self), dtype=np.int32) | ||
sorted_index = np.empty(len(self), dtype=np.int32) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Orthogonal to this but I wonder why this is specified as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. numpy uses int32 for argsort so best can do (to be honest 2B is enough) |
||
|
||
bad = isna(arr) | ||
|
||
|
@@ -2844,16 +2849,19 @@ def _try_kind_sort(arr): | |
|
||
if na_position == "last": | ||
n = good.sum() | ||
sortedIdx[:n] = idx[good][argsorted] | ||
sortedIdx[n:] = idx[bad] | ||
sorted_index[:n] = idx[good][argsorted] | ||
sorted_index[n:] = idx[bad] | ||
elif na_position == "first": | ||
n = bad.sum() | ||
sortedIdx[n:] = idx[good][argsorted] | ||
sortedIdx[:n] = idx[bad] | ||
sorted_index[n:] = idx[good][argsorted] | ||
sorted_index[:n] = idx[bad] | ||
else: | ||
raise ValueError(f"invalid na_position: {na_position}") | ||
|
||
result = self._constructor(arr[sortedIdx], index=self.index[sortedIdx]) | ||
result = self._constructor(arr[sorted_index], index=self.index[sorted_index]) | ||
|
||
if ignore_index: | ||
jreback marked this conversation as resolved.
Show resolved
Hide resolved
|
||
result.index = ibase.default_index(len(sorted_index)) | ||
|
||
if inplace: | ||
self._update_inplace(result) | ||
|
Uh oh!
There was an error while loading. Please reload this page.