-
Notifications
You must be signed in to change notification settings - Fork 920
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
Refactor Index
search to simplify code and increase correctness
#13625
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The generic ColumnBase class can implement find_first and find_last by asking for the indices of a given value. It is this latter which must be implemented in a subclass-specific way. Also remove the closest argument and implementation of get_slice_bounds which is an Index-specific function.
Indices are immutable, so this property can be cached. We will use this to implement faster and more correct searches.
With specialised handling for RangeIndex
wence-
added
bug
Something isn't working
Python
Affects Python cuDF API.
improvement
Improvement / enhancement to an existing function
labels
Jun 27, 2023
This is partially prep work for the followon to #13534 that will implement |
When the indices are sorted, we need to a bit more work in get_slice_bound to handle those cases. But having done so correctly we can push the implementation of find_label_range to BaseIndex and just specialise get_slice_bound in specific implementations. - Closes rapidsai#12833
Now that we have indices_of available on index objects, use that when looking up scalar values in an index for loc-based indexing. - Closes rapidsai#8693
wence-
force-pushed
the
wence/fea/indexes
branch
from
June 27, 2023 15:56
901b31c
to
c7b22dd
Compare
wence-
force-pushed
the
wence/fea/indexes
branch
from
June 27, 2023 16:03
c7b22dd
to
19f4e11
Compare
shwina
reviewed
Jun 28, 2023
wence-
commented
Jun 28, 2023
With this, the implementation of get_slice_bound can also be shared amongst all index types.
This was previously the case, but now we have moved the implementation to BaseIndex we must override here.
shwina
approved these changes
Jun 30, 2023
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.
Nice work!
/merge |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
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.
Description
Much of the index-specific search code for label-based lookup only worked in the case where the index was sorted in ascending order and/or the requested slice had the same step sign as the index. To fix this, handle ascending and descending sorted indices specially, as well as refactoring to remove unused codepaths.
The core idea is to push
find_first
andfind_last
to being generic column methods (in doing so we remove theclosest
argument, but that was only used to produce pandas-incompatible index behaviour).Lookup in indices then uses
get_slice_bound
(that can be specialised for index types) that uses first (if applicable)searchsorted
and thenfind_first/last
.While we're here, since we now check the sortedness properties of Index objects, turn them into
@cached_property
(partially addressing the request of #13357).loc
behavior differs from pandas when a duplicated index is requested #8693loc
-based indexing with slice ranges inconsistent with pandas #12833Checklist