Description
Code Sample, a copy-pastable example if possible
pi = pd.period_range(start=2000, end=2019, freq="A")
p = pd.Period(2010, freq="A")
In [7]: pi._engine.get_loc(p)
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-7-cd77985ba7c9> in <module>
----> 1 pi._engine.get_loc(p)
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas/_libs/index_class_helper.pxi in pandas._libs.index.Int64Engine._check_type()
KeyError: Period('2010', 'A-DEC')
Problem description
When i handled #28628, i found PeriodEngine
only works for Int type. So PeriodIndex.get_loc
compute twice because PeriodEngine.get_loc
only accepts Int type.
Suggestion
.get_loc
on PeriodIndex
computes once. Either expanding PeriodEngine.get_loc
accept data type or removeing PeriodEngine.get_loc
are ok
Output of pd.show_versions()
[paste the output of pd.show_versions()
here below this line]
INSTALLED VERSIONS
commit : None
python : 3.7.1.final.0
python-bits : 64
OS : Linux
OS-release : 5.0.0-31-generic
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : ko_KR.UTF-8
LOCALE : ko_KR.UTF-8
pandas : 0.25.1
numpy : 1.16.1
pytz : 2018.7
dateutil : 2.7.5
pip : 19.3
setuptools : 40.6.3
Cython : 0.29.2
pytest : 5.1.0
hypothesis : None
sphinx : 1.8.2
blosc : None
feather : None
xlsxwriter : 1.1.2
lxml.etree : 4.2.5
html5lib : 1.0.1
pymysql : 0.9.3
psycopg2 : None
jinja2 : 2.10.1
IPython : 7.2.0
pandas_datareader: None
bs4 : 4.8.0
bottleneck : 1.2.1
fastparquet : None
gcsfs : None
lxml.etree : 4.2.5
matplotlib : 3.0.2
numexpr : 2.6.8
odfpy : None
openpyxl : 2.5.12
pandas_gbq : None
pyarrow : None
pytables : None
s3fs : None
scipy : 1.1.0
sqlalchemy : 1.2.15
tables : 3.4.4
xarray : None
xlrd : 1.2.0
xlwt : 1.3.0
xlsxwriter : 1.1.2