-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
PERF: CategoricalDtype.__eq__ #36280
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2845100
PERF: CategoricalDtype.__eq__
jbrockmendel 4680cd4
Merge branch 'master' of https://github.com/pandas-dev/pandas into pe…
jbrockmendel 0ef1393
Merge branch 'master' of https://github.com/pandas-dev/pandas into pe…
jbrockmendel 0091f5f
comment
jbrockmendel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -375,12 +375,30 @@ def __eq__(self, other: Any) -> bool: | |
# but same order is not necessary. There is no distinction between | ||
# ordered=False and ordered=None: CDT(., False) and CDT(., None) | ||
# will be equal if they have the same categories. | ||
if ( | ||
self.categories.dtype == other.categories.dtype | ||
and self.categories.equals(other.categories) | ||
): | ||
left = self.categories | ||
right = other.categories | ||
|
||
# GH#36280 the ordering of checks here is for performance | ||
if not left.dtype == right.dtype: | ||
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_dtype_equal 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. thatd require a circular import (actually id like to put is_dtype_equal "above" this file, but thats for another day) |
||
return False | ||
|
||
if len(left) != len(right): | ||
return False | ||
|
||
if self.categories.equals(other.categories): | ||
# Check and see if they happen to be identical categories | ||
return True | ||
|
||
if left.dtype != object: | ||
jreback marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# Faster than calculating hash | ||
indexer = left.get_indexer(right) | ||
# Because left and right have the same length and are unique, | ||
# `indexer` not having any -1s implies that there is a | ||
# bijection between `left` and `right`. | ||
return (indexer != -1).all() | ||
|
||
# With object-dtype we need a comparison that identifies | ||
# e.g. int(2) as distinct from float(2) | ||
return hash(self) == hash(other) | ||
|
||
def __repr__(self) -> str_type: | ||
|
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.
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.
can you add a comment that the ordering of checks is for perf