-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
API: Allow equality comparisons of Series with a categorical dtype and object type are allowed (GH8938) #8946
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
Conversation
@jorisvandenbossche ? |
Probably want to make sure |
@shoyer good point, fixed up. |
self.assertTrue(((~(f==a)==(f!=a)).all())) | ||
|
||
# non-equality is not comparable | ||
self.assertRaises(TypeError, lambda: a < b) |
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'm not sure whether the codepath is different, but just to make sure that this doesn't slip in:
self.assertRaises(TypeError, lambda: a > b)
self.assertRaises(TypeError, lambda: b > a)
This should also get some updates in categorical.rst. Want to get a patch? |
@JanSchulz if you want to post a patch all ears! (for docs)....i'll fix the other in a minute |
Patch is at #8952 |
What I started to wonder when I did the docs: if On the other hand a scalar comparison with the categorical makes only sense if the scalar can be treated as a category (for any other value, it's basically a "not of the same type" comparison, which would raise on python3), so the scalar must be in
|
@JanSchulz I can kind of buy that last example we would 'like' to work (as it seems natural), but it does violate the Categorical principles. Ok, how about we merge this to fix the equalitiy inconsistency with merging then open a new issue for discussion about non-equal comparisons. ? |
…d object dtype are allowed (previously would raise TypeError) (GH8938)
@JanSchulz ok on this? |
Jep, I'll open a new issue with that.. |
Oh, one more thing: according to that thought, |
@JanSchulz gr8 thanks |
this is actually consistent (e.g. it returns
|
API: Allow equality comparisons of Series with a categorical dtype and object type are allowed (GH8938)
|
||
.. ipython:: python | ||
|
||
cat == cat_base2 |
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.
@JanSchulz @jreback This generates an error in the docs: TypeError: Categoricals can only be compared if 'categories' are the same
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.
change to this (or can make rhs [2,2,4]
(or whatever), just cannot be a categorical with different categories
In [14]: cat == np.array(cat_base2)
Out[14]:
0 False
1 True
2 False
dtype: bool
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.
or change to cat_base
instead of cat_base2
I suppose
closes #8938