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: Inconsistent behavior in Index.difference #35217

Closed
2 of 3 tasks
galipremsagar opened this issue Jul 10, 2020 · 1 comment · Fixed by #35231
Closed
2 of 3 tasks

BUG: Inconsistent behavior in Index.difference #35217

galipremsagar opened this issue Jul 10, 2020 · 1 comment · Fixed by #35231
Labels
Bug Index Related to the Index class or subclasses Numeric Operations Arithmetic, Comparison, and Logical operations
Milestone

Comments

@galipremsagar
Copy link

  • 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.


Index.difference seems to be treating float vs object / int vs object differently.

Code Sample, a copy-pastable example

import pandas as pd
float_index = pd.Index([1.0, 2, 3])
string_index = pd.Index(['1','2','3'])
integer_index = pd.Index([1, 2, 3])
print(float_index.difference(string_index))
print(string_index.difference(float_index))

print(integer_index.difference(string_index))
print(string_index.difference(integer_index))


Float64Index([], dtype='float64')
Index([], dtype='object')
Int64Index([1, 2, 3], dtype='int64')
Index(['1', '2', '3'], dtype='object')

Problem description

Index.difference should probably not type-cast and compare the elements to honor consistent behavior with other types where they are not being type-casted.

Expected Output

Float64Index([1.0, 2.0, 3.0], dtype='float64')
Index(['1', '2', '3'], dtype='object')
Int64Index([1, 2, 3], dtype='int64')
Index(['1', '2', '3'], dtype='object')

or

All empty Index objects like in case of int vs object.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None

pandas : 1.0.5
numpy : 1.19.0
pytz : 2020.1
dateutil : 2.8.1
pip : 20.1.1
setuptools : 49.1.0
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
pytest : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
numba : None
None

@galipremsagar galipremsagar added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 10, 2020
@galipremsagar
Copy link
Author

After going through code this looks like an issue with Index.equals:

import pandas as pd
float_index = pd.Index([1.0, 2, 3])
string_index = pd.Index(['1','2','3'])
integer_index = pd.Index([1, 2, 3])
print(float_index.equals(string_index))
print(string_index.equals(float_index))

print(integer_index.equals(string_index))
print(string_index.equals(integer_index))

True
True
False
False

@simonjayhawkins simonjayhawkins added Index Related to the Index class or subclasses Numeric Operations Arithmetic, Comparison, and Logical operations and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 11, 2020
@jreback jreback added this to the 1.1 milestone Jul 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Index Related to the Index class or subclasses Numeric Operations Arithmetic, Comparison, and Logical operations
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants