BUG: Incorrect arithmetic with PeriodIndex · Issue #45999 · pandas-dev/pandas (original) (raw)
Pandas version checks
- I have checked that this issue has not already been reported.
- I have confirmed this bug exists on the latest version of pandas.
- I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
import pandas as pd periods = pd.period_range(start="2021-01-01", periods=3, freq="2H") periods - periods[0]
Issue Description
Period index simple arithmetic produces either unexpected, or even wrong results. In the provided example the output is
Index([<0 * Hours>, <4 * Hours>, <8 * Hours>], dtype='object')
Expected Behavior
Using list comprehension instead of PeriodIndex directly:
[v - periods[0] for v in periods]
produces:
[<0 * Hours>, <2 * Hours>, <4 * Hours>]
as expected.
Installed Versions
pd.show_versions()
INSTALLED VERSIONS
commit : 06d2301
python : 3.9.6.final.0
python-bits : 64
OS : Linux
OS-release : 5.13.0-28-generic
Version : #31-Ubuntu SMP Thu Jan 13 17:41:06 UTC 2022
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.4.1
numpy : 1.21.4
pytz : 2021.3
dateutil : 2.8.2
pip : 22.0.3
setuptools : 58.4.0
Cython : None
pytest : 6.2.5
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.0.3
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 6.0.1
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.7.3
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None