-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Categorical equality with NaN behaves unexpectedly #28384
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
Comments
cc @jorisvandenbossche (gets into the NA vs. NaN discussion as part of #28095). |
This is standard behavior per IEE 7544 So I think nothing to be done directly on this issue. If you have feedback on generally how missing values should be handled I would suggest rolling into linked issue above |
@WillAyd as noted in the issue, for other dtypes it does equate to True, as well for scalars:
|
To make the difference in behaviour between categorical and non-categorical very explicit:
I suppose this has to do with |
Just to further emphasize the problems this causes,
Result 5 makes sense, but 6 doesn't. It's impossible to successfully reason about a Pandas program when |
looks to be fixed on master (@jbrockmendel maybe #36237?)
|
take |
Code Sample, a copy-pastable example if possible
Output:
Problem description
I would expect anything to compare
!=
to NaN.Comparing the categorical series with
==
works as expected:Output:
Element-wise comparison seems to work fine:
Output:
This also works as expected with other data types, e.g.:
gives
Apologies if this is a duplicate; I have found various issues about categorical types and missing values, but not about comparing them in this way.
Expected Output
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : None
python : 3.7.4.final.0
python-bits : 64
OS : Darwin
OS-release : 16.7.0
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_GB.UTF-8
LOCALE : en_GB.UTF-8
pandas : 0.25.1
numpy : 1.17.2
pytz : 2019.2
dateutil : 2.8.0
pip : 19.2.2
setuptools : 41.0.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
The text was updated successfully, but these errors were encountered: