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: isin() give incorrect results for uint64 columns #46485

Closed
3 tasks done
AlexSingle opened this issue Mar 23, 2022 · 5 comments · Fixed by #46693
Closed
3 tasks done

BUG: isin() give incorrect results for uint64 columns #46485

AlexSingle opened this issue Mar 23, 2022 · 5 comments · Fixed by #46693
Assignees
Labels
Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Bug Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@AlexSingle
Copy link

Pandas version checks

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

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

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd
import numpy as np
test_df = pd.DataFrame([{'a': 1378774140726870442}], dtype=np.uint64)
test_df[test_df['a'].isin([1378774140726870528])]
                     a
0  1378774140726870442
test_df[test_df['a'].isin([1378774140726870522])]
                     a
0  1378774140726870442

Issue Description

I have column in uin64 and want to check if values in some list. but isin returning incorrect results. I suspect where some Implicit type conversion, cause I was't able to reproduce for other types

Expected Behavior

For examples I expected empty DataFrame in both cases

Installed Versions

INSTALLED VERSIONS

commit : 06d2301
python : 3.8.10.final.0
python-bits : 64
OS : Linux
OS-release : 4.19.100-23
Version : #1 SMP Fri Jan 31 16:16:00 UTC 2020
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.4.1
numpy : 1.21.2
pytz : 2020.5
dateutil : 2.8.2
pip : 20.0.2
setuptools : 58.2.0
Cython : 0.29.24
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.6.3
html5lib : None
pymysql : None
psycopg2 : 2.9.1
jinja2 : 3.0.2
IPython : 7.28.0
pandas_datareader: None
bs4 : 4.10.0
bottleneck : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.4.3
numba : None
numexpr : None
odfpy : None
openpyxl : 3.0.9
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.7.1
sqlalchemy : 1.4.25
tables : None
tabulate : 0.8.9
xarray : None
xlrd : None
xlwt : None
zstandard : None

@AlexSingle AlexSingle added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Mar 23, 2022
@Saxeman
Copy link

Saxeman commented Mar 23, 2022

take

@Saxeman
Copy link

Saxeman commented Mar 23, 2022

It seems when I run it and print the output it says that both of them are empty dataframes, could that 0 just be so that the data can be viewed? I may be misunderstanding the bug, but to me it seems like it could be intended behavior.

@AlexSingle
Copy link
Author

In real case i wanted to filer out DataFrame by some values, but it keeps returning wrong values, what not supposed to be in it. So i believe, what is not for viewing purpose, it should return DataFrame, that contains values from isin(). And if there is none, it should return empty DataFrame. For example. this is expected behavior

test_df[test_df['a'].isin([1])]
Empty DataFrame
Columns: [a]
Index: []

I constantly reproduce bug in two different os and in random online python interpreter. And i find out, that bug not present in version 1.1.5.

@Saxeman
Copy link

Saxeman commented Mar 24, 2022

Apologies for asking, but could you restate that? I am having a little trouble understanding what you mean in your explanation.

@AlexSingle
Copy link
Author

Oh, sorry. Let me try a more clear example

import pandas as pd
import numpy as np
test_df = pd.DataFrame([{'a': 1378774140726870442}], dtype=np.uint64)

print(1378774140726870442 == 1378774140726870528) 
False

print(test_df['a'].isin([1378774140726870528])[0])
True

 print(test_df['a'].isin([1])[0])
False

I expected tha isin() return True only if any value in column presented in list, that is argument for isin(). In this example isin() sometimes returns true for clearly different numbers. I encountered this behaviour only for unit64 column and for big enough numbers. And in pandas==1.1.15 isn() working as expected.

@phofl phofl added Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 8, 2022
@phofl phofl added the Regression Functionality that used to work in a prior pandas version label Apr 8, 2022
@jreback jreback added this to the 1.5 milestone Apr 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Bug Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants