reindex with Period results in NaN · Issue #28337 · pandas-dev/pandas (original) (raw)

Code Sample, a copy-pastable example if possible

idx1 = pd.MultiIndex.from_tuples( [ ("x", Period("2019Q1", "Q-DEC")), ("x", Period("2019Q2", "Q-DEC")), ] )

idx2 = pd.MultiIndex.from_tuples( [ ("x", Period("2019Q1", "Q-DEC")), ("x", Period("2019Q2", "Q-DEC")), ("x", "All"), ] )

s = pd.Series([1.0, 1.0], index=idx1)

x 2019Q1 1.0 2019Q2 1.0 dtype: float64

ACTUAL

s.reindex(idx2)

x 2019Q1 NaN 2019Q2 NaN All NaN dtype: float64

EXPECTED

x 2019Q1 1.0 2019Q2 1.0 All NaN dtype: float64

Problem description

This is the underlying problem causing #28323. Reindexing with an index that contains a Period results in NaN results.

Output of pd.show_versions()

INSTALLED VERSIONS

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

pandas : 0.25.1
numpy : 1.17.2
pytz : 2019.2
dateutil : 2.8.0
pip : 19.2.2
setuptools : 41.0.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.10.1
IPython : 7.8.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None