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 does some inconsistent type casting? #34125

Closed
3 tasks done
phofl opened this issue May 11, 2020 · 2 comments
Closed
3 tasks done

BUG: isin does some inconsistent type casting? #34125

phofl opened this issue May 11, 2020 · 2 comments
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions isin isin method

Comments

@phofl
Copy link
Member

phofl commented May 11, 2020

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

  • 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. (exists on the version I checked out 2 weeks ago)

I observed the following behavior:

When I define my DataFrame with a numeric column like

import pandas as pd
df = pd.DataFrame({"a": [1, 2]})

and filter with isin() for "1" like

df["a"].isin(["1"])

I get

0     True
1    False
Name: a, dtype: bool

which results probably from implicit type casting?

But when my column has datatype object like

df = pd.DataFrame({"a": [1, "2"]})

and filter again with isin()

df["a"].isin(["1"])

I get the following:

0    False
1    False
Name: a, dtype: bool

That was the output I expected.
This seems a bit inconsistent. Is this the expected behavior? If not, I would look into this, if I have a bit of time in the coming weeks. This may be loosely related to #19356 .

Output of pd.show_versions()

python : 3.7.7.final.0
python-bits : 64
OS : Linux
OS-release : 4.15.0-99-generic
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.0.1
numpy : 1.18.1
pytz : 2019.3
dateutil : 2.8.1
pip : 20.0.2
setuptools : 46.1.3.post20200330
Cython : 0.29.15
pytest : 5.4.1
hypothesis : 5.8.3
sphinx : 2.4.4
blosc : None
feather : None
xlsxwriter : 1.2.8
lxml.etree : 4.5.0
html5lib : 1.0.1
pymysql : None
psycopg2 : None
jinja2 : 2.11.1
IPython : 7.13.0
pandas_datareader: None
bs4 : 4.8.2
bottleneck : 1.3.2
fastparquet : None
gcsfs : None
lxml.etree : 4.5.0
matplotlib : 3.1.3
numexpr : 2.7.1
odfpy : None
openpyxl : 3.0.3
pandas_gbq : None
pyarrow : None
pytables : None
pytest : 5.4.1
pyxlsb : None
s3fs : None
scipy : 1.4.1
sqlalchemy : 1.3.13
tables : 3.6.1
tabulate : None
xarray : None
xlrd : 1.2.0
xlwt : 1.3.0
xlsxwriter : 1.2.8
numba : 0.49.0

@phofl phofl added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels May 11, 2020
@charlesdong1991 charlesdong1991 added Dtype Conversions Unexpected or buggy dtype conversions Indexing Related to indexing on series/frames, not to indexes themselves and removed Needs Triage Issue that has not been reviewed by a pandas team member labels May 12, 2020
@gabrielvf1
Copy link
Contributor

gabrielvf1 commented May 13, 2020

Working on this one, ok?

@phofl
Copy link
Member Author

phofl commented Jan 9, 2021

@phofl phofl closed this as completed Jan 9, 2021
@phofl phofl added this to the No action milestone Jan 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions isin isin method
Projects
None yet
Development

No branches or pull requests

4 participants