Skip to content

BUG: IntervalIndex.get_indexer fails for homogeneous Period targets #30178

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 Dec 10, 2019 · 3 comments · Fixed by #47816
Closed

BUG: IntervalIndex.get_indexer fails for homogeneous Period targets #30178

jschendel opened this issue Dec 10, 2019 · 3 comments · Fixed by #47816
Assignees
Labels
good first issue Indexing Related to indexing on series/frames, not to indexes themselves Interval Interval data type Needs Tests Unit test(s) needed to prevent regressions Period Period data type

Comments

@jschendel
Copy link
Member

Code Sample, a copy-pastable example if possible

In [1]: import pandas as pd; pd.__version__
Out[1]: '0.26.0.dev0+1256.g52f5fdf10'

In [2]: ii = pd.interval_range(pd.Timestamp('2018-01-01'), freq='3D', periods=3)

In [3]: pi = pd.period_range('2018-01-01', freq='D', periods=3)

In [4]: ii.get_indexer(pi)
---------------------------------------------------------------------------
TypeError: No matching signature found

In [5]: ii.get_indexer(pd.array(pi))
---------------------------------------------------------------------------
TypeError: No matching signature found

In [6]: ii.get_indexer(list(pi))
---------------------------------------------------------------------------
TypeError: No matching signature found

Note that heterogeneous targets containing Period objects are okay, as they get coerced to object dtype:

In [7]: ii.get_indexer(list(pi) + [10])
Out[7]: array([-1, -1, -1, -1])

xref #30063 (comment)

Problem description

Homogeneous Period targets incorrectly raise a TypeError for IntervalIndex.get_indexer.

Expected Output

I'd expect IntervalIndex.get_indexer to return an array indicating all values are missing (-1) for homogeneous Period targets.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 52f5fdf
python : 3.7.4.final.0
python-bits : 64
OS : Linux
OS-release : 4.19.14-041914-generic
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 0.26.0.dev0+1256.g52f5fdf10
numpy : 1.17.2
pytz : 2019.2
dateutil : 2.8.0
pip : 19.2.3
setuptools : 41.6.0.post20191030
Cython : 0.29.13
pytest : 5.2.0
hypothesis : 4.36.2
sphinx : 1.8.5
blosc : None
feather : None
xlsxwriter : 1.2.1
lxml.etree : 4.4.1
html5lib : 1.0.1
pymysql : None
psycopg2 : None
jinja2 : 2.10.1
IPython : 7.8.0
pandas_datareader: None
bs4 : 4.8.0
bottleneck : 1.2.1
fastparquet : 0.3.2
gcsfs : None
lxml.etree : 4.4.1
matplotlib : 3.1.1
numexpr : 2.7.0
odfpy : None
openpyxl : 3.0.0
pandas_gbq : None
pyarrow : 0.15.0
pytables : None
pytest : 5.2.0
s3fs : 0.3.4
scipy : 1.3.1
sqlalchemy : 1.3.8
tables : 3.5.1
xarray : 0.13.0
xlrd : 1.2.0
xlwt : 1.3.0
xlsxwriter : 1.2.1

@jschendel jschendel added Bug Indexing Related to indexing on series/frames, not to indexes themselves Period Period data type Interval Interval data type labels Dec 10, 2019
@jschendel jschendel added this to the Contributions Welcome milestone Dec 10, 2019
@mroeschke
Copy link
Member

This looks to work on master. Could use a test

In [2]:
   ...: In [2]: ii = pd.interval_range(pd.Timestamp('2018-01-01'), freq='3D', periods=3)
   ...:
   ...: In [3]: pi = pd.period_range('2018-01-01', freq='D', periods=3)
   ...:
   ...: In [4]: ii.get_indexer(pi)
Out[2]: array([-1, -1, -1])

In [3]: In [5]: ii.get_indexer(pd.array(pi))
Out[3]: array([-1, -1, -1])

In [4]: In [6]: ii.get_indexer(list(pi))
Out[4]: array([-1, -1, -1])

@mroeschke mroeschke added good first issue Needs Tests Unit test(s) needed to prevent regressions and removed Bug labels Jul 23, 2021
@itsguneetsingh
Copy link

I am a first timer and I don't know what exactly you would want in the test. Could you maybe help by telling exactly you're looking for in the test??

@parthi-siva
Copy link
Contributor

take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Indexing Related to indexing on series/frames, not to indexes themselves Interval Interval data type Needs Tests Unit test(s) needed to prevent regressions Period Period data type
Projects
None yet
4 participants