Bug: Save original index and remap after function completes #61116
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.Note: I'm new to this project, so this is my first PR.
Saves the index for SeriesNLargest at algorithm start and resets it before returning. This fixes performance issues when the index has many duplicate values.
Results:
Tests
The existing tests should cover this unless we want to add specific tests via the
asv_bench
.Addendum
I also modified the call to sort to use
sort(kind="stable")
to get consistent ordering which is what is currently happening in the equivalent Frame method (it was usingkind=mergesort
which is equivalent tokind=stable
, but kept for portability). I can remove this -- it may be better in another PR.https://numpy.org/doc/stable/reference/generated/numpy.sort.html#numpy.sort