-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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
ENH: Add ignore_index for df.sort_values and series.sort_values #30402
Changes from 16 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 |
---|---|---|
|
@@ -474,6 +474,7 @@ Other API changes | |
Supplying anything else than ``how`` to ``**kwargs`` raised a ``TypeError`` previously (:issue:`29388`) | ||
- When testing pandas, the new minimum required version of pytest is 5.0.1 (:issue:`29664`) | ||
- :meth:`Series.str.__iter__` was deprecated and will be removed in future releases (:issue:`28277`). | ||
- ``ignore_index`` is added in :meth:`DataFrame.sort_values` and :meth:`Series.sort_values` to be able to reset index after sorting (:issue:`30114`) | ||
|
||
|
||
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. move this to other enhancements |
||
.. _whatsnew_1000.api.documentation: | ||
|
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,8 @@ 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. | ||
|
||
Returns | ||
------- | ||
|
@@ -2855,6 +2858,9 @@ def _try_kind_sort(arr): | |
|
||
result = self._constructor(arr[sortedIdx], index=self.index[sortedIdx]) | ||
|
||
if ignore_index: | ||
jreback marked this conversation as resolved.
Show resolved
Hide resolved
|
||
result = result.reset_index(drop=True) | ||
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. Is there a reason for this to differ with the frame implementation? Should be the same in both cases 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. oh, sorry! I thought the other one was faster in the first place, and then later found basically no difference, and forgot to align them to keep consistency. Changed! thanks! @WillAyd 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. ahh!! i recall why they are different, this 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. use this is NOT a BlockManager here, but a series 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. ahh, sorry for my bad English, i meant 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. you will see my comment in the PR about drop_duplicates. We do not want to use .reset_index directly at all. This causes yet another copy of the data which we can easily avoid here. you have to be careful to avoid mutating things though. |
||
|
||
if inplace: | ||
self._update_inplace(result) | ||
else: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reverse the ordering a bit
:meth:`DataFrame.sort_values` and :meth:`Series.sort_values`
have gained theignore_index
......There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed and moved!