Skip to content

BUG: IntervalIndex scalar lookup raises for included right endpoints when sorted decreasing. #16417

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
jschendel opened this issue May 22, 2017 · 0 comments · Fixed by #17272
Closed
Labels
Indexing Related to indexing on series/frames, not to indexes themselves Internals Related to non-user accessible pandas implementation
Milestone

Comments

@jschendel
Copy link
Member

Code Sample, a copy-pastable example if possible

# Series definition
ivs = [pd.Interval(10, 12), pd.Interval(7, 9), pd.Interval(4, 6), pd.Interval(1, 3)]
s = pd.Series(['foo', 'bar', 'baz', 'qux'], pd.IntervalIndex(ivs))

(10, 12]    foo
(7, 9]      bar
(4, 6]      baz
(1, 3]      qux
dtype: object

# Scalar lookup of included right endpoint raises a KeyError.
s[12]
KeyError: 12

Problem description

The right endpoint is included in the interval (10, 12], so a KeyError should not be raised for s[12]. This occurs for all endpoints (12, 9, 6, 3) in the example above. Using loc also raises.

This issue only occurs when the intervals are sorted decreasing; the lookup is successful for any other permutation of the interval order, e.g. [pd.Interval(7, 9), pd.Interval(10, 12), pd.Interval(4, 6), pd.Interval(1, 3)]. It also only occurs for right endpoints (closed='right' or closed='both'); when the left endpoints are included (closed='left' or closed='both') the lookup is successful for all left endpoints for any ordering of the intervals.

This seems similar to #16410, but I don't know that it's an exact dupe.

Expected Output

Successful lookup

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.5.2.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 78 Stepping 3, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None

pandas: 0.20.1
pytest: 3.0.7
pip: 9.0.1
setuptools: 34.4.1
Cython: 0.25.2
numpy: 1.13.0rc2
scipy: 0.18.1
xarray: 0.9.5
IPython: 5.3.0
sphinx: None
patsy: 0.4.1
dateutil: 2.6.0
pytz: 2017.2
blosc: 1.4.4
bottleneck: 1.2.0
tables: 3.4.2
numexpr: 2.6.1
feather: None
matplotlib: 2.0.2
openpyxl: 2.4.0
xlrd: 1.0.0
xlwt: None
xlsxwriter: None
lxml: 3.7.3
bs4: None
html5lib: None
sqlalchemy: 1.1.10
pymysql: None
psycopg2: None
jinja2: 2.9.6
s3fs: None
pandas_gbq: 0.1.6
pandas_datareader: 0.4.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Indexing Related to indexing on series/frames, not to indexes themselves Internals Related to non-user accessible pandas implementation
Projects
None yet
3 participants