IntervalIndex get_indexer may return -1 for values that are in the index · Issue #16410 · pandas-dev/pandas (original) (raw)

Code Sample, a copy-pastable example if possible

idx = pd.IntervalIndex.from_breaks(pd.np.arange(10)) target = pd.Interval(0, 1, closed='right')

Indexer works in this case if index was sorted

a = idx.get_indexer([target]) assert a[0] == 0

idx = pd.Index(pd.np.roll(idx.values, 1)) a = idx.get_indexer([target]) assert tmp == idx[1]

Even though the second value in the index is equal to the target get_indexer returns -1

a[0]

-1

Problem description

I expected get_indexer on IntervalIndex is expected to return the index of matching values. However it does not always seem to do so.

Expected Output

In the above example I expected an output of a = np.array([1])

Output of pd.show_versions()

INSTALLED VERSIONS

commit: 4111382
python: 3.5.2.final.0
python-bits: 64
OS: Darwin
OS-release: 16.5.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.21.0.dev+67.g4111382
pytest: 3.0.7
pip: 8.1.2
setuptools: 35.0.2
Cython: 0.25.2
numpy: 1.12.1
scipy: 0.19.0
xarray: None
IPython: 5.1.0
sphinx: 1.4.8
patsy: None
dateutil: 2.6.0
pytz: 2017.2
blosc: None
bottleneck: 1.2.0
tables: 3.3.0
numexpr: 2.6.2
feather: None
matplotlib: 2.0.0
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
sqlalchemy: 1.1.2
pymysql: 0.7.9.None
psycopg2: None
jinja2: 2.8
s3fs: None
pandas_gbq: None
pandas_datareader: None