-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: Fix __ne__ comparison for Categorical #32304
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 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
cd44bf4
Special case __ne__
dsaxton 3c621fb
Test
dsaxton b3adfe2
Doc
dsaxton 70f7ebb
Reference self
dsaxton 0087a53
Blacken
dsaxton 94d6238
Don't use mask
dsaxton 888f7cf
Param over categories
dsaxton be39621
Merge remote-tracking branch 'upstream/master' into noteq-cat
dsaxton 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
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
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 |
---|---|---|
|
@@ -282,6 +282,16 @@ def _compare_other(self, s, data, op_name, other): | |
with pytest.raises(TypeError, match=msg): | ||
op(data, other) | ||
|
||
def test_not_equal_with_na(self): | ||
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. do we get this right in cases with e.g. datetime64 or datetime64tz categories? 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. It seems to work, added some parameterization over other category types |
||
# https://github.com/pandas-dev/pandas/issues/32276 | ||
categories = ["a", "b"] | ||
c1 = Categorical([None, "a"], categories=categories) | ||
c2 = Categorical(["a", "b"], categories=categories) | ||
|
||
result = c1 != c2 | ||
|
||
assert result.all() | ||
|
||
|
||
class TestParsing(base.BaseParsingTests): | ||
pass |
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.
This redundancy was intentional and an attempt to "reuse" the
mask
calculation above since I think it may short-circuit whenmask
isFalse
, but could just make it(self._codes == -1) & (other_codes == -1)
as well. I also think__ne__
is the only situation that'd have to be special-cased here out of the comparison operators. Also worth pointing out that this is assuming we're dealing withNaN
rather thanNA
.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.
I think this would be more clear. Also there might be a cached
_isnan
attribute for thisThere 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.
@dsaxton im working on cleaning up these comparisons, am confused by this line. can we make this use the more common pattern
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.
@jbrockmendel That is much simpler and seems correct to me