-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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
BUG: Datetimelike equality comparisons with Categorical #30699
Comments
Worthwhile to note that equality comparisons for non-datetimelike vs. equivalent categoricals looks to be working (intervals being fixed in #30640). Also looks like #30654 addresses the issue of |
Does it work with the Categorical on the left? i.e. will it be sufficient to make the DTA/PA ops return NotImplemented? |
No, it works in a few additional cases that way but not for all cases, e.g. In [1]: import pandas as pd; pd.__version__
Out[1]: '0.26.0.dev0+1637.g6d67cf9f0'
In [2]: dti_tz = pd.date_range("2020", periods=3, tz="UTC")
In [3]: pd.Categorical(dti_tz) == dti_tz
Out[3]: array([False, False, False])
In [4]: pd.Categorical(dti_tz) == dti_tz.array
Out[4]: array([False, False, False]) |
Working on this |
Looks like all these work as expected now. Could use tests
|
The equality cases are fixed by #34055, but the inequality cases are still outstanding |
Appears that the inequality cases are correctly returning an array of
|
i think it depends on if the Categorical is ordered. if not then these should raise |
take |
@jbrockmendel What exact behaviour did you mean to check here? I believe other inequalities from the snippet of @mroeschke are already covered by #34055 |
If a categorical is not ordered, then basically any inequality checks should raise TypeError. |
take |
Code Sample, a copy-pastable example if possible
Consider the following setup on master:
Equality comparisons with an equivalent
Categorical
are incorrect forDatetimeIndex
:Equality comparisons raise for
PeriodIndex
:Looks good for
TimedeltaIndex
:The incorrect behavior above is generally consistent when replacing the index with its extension array/Series equivalent,
Categorical
withCategoricalIndex
/Series[Categorical]
, and==
with!=
.The only exception appears to be that a couple cases work when when you have a
Categorical
/CategoricalIndex
on the RHS and an extension array on the LHS:Though note that the above does not work for
dti_tz.array
Problem description
Equality comparisons for datetimelike arrays/indexes are largely incorrect when comparing to equivalent categoricals. There is some tie in to #19513 but I think this specific component is pretty clear cut.
Expected Output
I'd expect all variants of
==
to in the examples above to returnarray([ True, True, True])
, and all variants of!=
to returnarray([False, False, False])
.cc @jbrockmendel
The text was updated successfully, but these errors were encountered: