Skip to content

Inconsistencies in index comparisons #12346

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

Closed
csiz opened this issue Feb 16, 2016 · 1 comment
Closed

Inconsistencies in index comparisons #12346

csiz opened this issue Feb 16, 2016 · 1 comment
Labels
Error Reporting Incorrect or improved errors from pandas Indexing Related to indexing on series/frames, not to indexes themselves Usage Question

Comments

@csiz
Copy link

csiz commented Feb 16, 2016

Comparing indexes returns two different data types. This is problematic since one of the types is a bool while the other is a Series which explicitly can't be treated in a bool context. Not to mention that the next section says == returns a Series object.

import pandas as pd

print pd.__version__
#0.14.0

index = pd.Int64Index([1, 2, 3])

print index == pd.Int64Index([])
# False
print index == pd.Int64Index([1])
# [True, False, False]
print index == pd.Int64Index([1, 2])
# False
print index == pd.Int64Index([4, 5, 6])
# [False, False, False]

series = pd.Series([1, 2, 3])

print series == pd.Series([1, 2])
# ValueError: Series lengths must match to compare

I'd suggest that comparing indexes with different lengths raise a ValueError like Series do. Possibly keeping the 1 element vs many as a special case

@jreback jreback added Indexing Related to indexing on series/frames, not to indexes themselves Usage Question Error Reporting Incorrect or improved errors from pandas labels Feb 16, 2016
@jreback
Copy link
Contributor

jreback commented Feb 16, 2016

You are using a pretty old version of pandas, IIRC this was corrected in 0.16.1 or so. Current is 0.17.1, and 0.18.0 is coming out shortly

In [81]: index = pd.Int64Index([1, 2, 3])

In [82]: index == pd.Int64Index([])
ValueError: Lengths must match to compare

In [83]: index == pd.Int64Index([1])
ValueError: Lengths must match to compare

In [85]: index == pd.Int64Index([1, 2])
ValueError: Lengths must match to compare

In [86]: index == pd.Int64Index([4, 5, 6])
Out[86]: array([False, False, False], dtype=bool)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas Indexing Related to indexing on series/frames, not to indexes themselves Usage Question
Projects
None yet
Development

No branches or pull requests

2 participants