Skip to content
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: Unexpected behaviour comparison dataframes with None values #34975

Closed
1 task
rosekoopman opened this issue Jun 24, 2020 · 6 comments
Closed
1 task

BUG: Unexpected behaviour comparison dataframes with None values #34975

rosekoopman opened this issue Jun 24, 2020 · 6 comments
Labels

Comments

@rosekoopman
Copy link

  • [x ] I have checked that this issue has not already been reported.

  • [ x] I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

np.nan == np.nan
# False

pd.Series(index=[0], data=[np.nan]) == pd.Series(index=[0], data=[np.nan])
# False

None == None
# True

pd.Series(index=[0], data=[None]) == pd.Series(index=[0], data=[None])
# False

Problem description

If None==None equals True, I had expected that pd.Series(index=[0], data=[None]) == pd.Series(index=[0], data=[None]) would also equal True.

I have pandas version 1.0.5

Expected Output

pd.Series(index=[0], data=[None]) == pd.Series(index=[0], data=[None])

True

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.6.10.final.0
python-bits : 64
OS : Linux
OS-release : 4.14.171-105.231.amzn1.x86_64
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.0.5
numpy : 1.16.2
pytz : 2019.3
dateutil : 2.8.0
pip : 20.0.2
setuptools : 46.1.3.post20200330
Cython : None
pytest : 5.3.5
hypothesis : None
sphinx : 2.4.3
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.5.0
html5lib : None
pymysql : None
psycopg2 : 2.8.4 (dt dec pq3 ext lo64)
jinja2 : 2.11.1
IPython : 7.12.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : 4.5.0
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 0.15.1
pytables : None
pytest : 5.3.5
pyxlsb : None
s3fs : 0.4.0
scipy : 1.4.1
sqlalchemy : 1.3.13
tables : None
tabulate : 0.8.6
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
numba : None

@rosekoopman rosekoopman added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jun 24, 2020
@mroeschke
Copy link
Member

@dsaxton
Copy link
Member

dsaxton commented Jun 24, 2020

@mroeschke While this is expected for None there's an almost identical issue for object NA which does seem like a bug:

In [3]: ser = pd.Series([pd.NA])                                                                                                                                                                             

In [4]: ser == ser                                                                                                                                                                                           
Out[4]: 
0    False
dtype: bool

Does it make sense to modify this / leave it open to track this? I think it's due to the same line:

if checknull(x) or checknull(y):

@mroeschke
Copy link
Member

Might be better to open up a separate issue for object NA.

I haven't followed NA semantics too closely but shouldn't that comparison also resolve to False or does the spec say it should be True?

@dsaxton
Copy link
Member

dsaxton commented Jun 24, 2020

Might be better to open up a separate issue for object NA.

I haven't followed NA semantics too closely but shouldn't that comparison also resolve to False or does the spec say it should be True?

The comparison should resolve to NA since the equality is "unknown", @rosekoopman would you be interested in opening up an issue for that?

@rosekoopman
Copy link
Author

@mroeschke : thanks for the explanation.

@dsaxton : yes I can open a new issue. However, the documentation linked by @mroeschke seems to suggest that False is the expected behaviour:

One has to be mindful that in Python (and NumPy), the nan's don’t compare equal, but None's do. Note that pandas/NumPy uses the fact that np.nan != np.nan, and treats None like np.nan.

@dsaxton
Copy link
Member

dsaxton commented Jun 25, 2020

@rosekoopman Actually let's not worry about opening another, looks like the issue is known and tracked here: #32931

@bashtage bashtage removed the Needs Triage Issue that has not been reviewed by a pandas team member label Aug 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants