Unable to add Timedelta to a Timestamp Interval · Issue #32023 · pandas-dev/pandas (original) (raw)

Code Sample, a copy-pastable example if possible

import pandas as pd year_2017 = pd.Interval(pd.Timestamp('2017-01-01 00:00:00'), pd.Timestamp('2018-01-01 00:00:00')) year_2017 Interval('2017-01-01', '2018-01-01', closed='right')

year_2017 + pd.Timedelta(days=7) Traceback (most recent call last): File "", line 1, in TypeError: unsupported operand type(s) for +: 'pandas._libs.interval.Interval' and 'Timedelta'

Problem description

From the pd.Interval documentation:

You can operate with + and * over an Interval and the operation is applied to each of its bounds, so the result depends on the type of the bound elements

However , we can apply the + operation manually on each bounds:

(year_2017.left + pd.Timedelta(days=7), year_2017.right + pd.Timedelta(days=7) ) (Timestamp('2017-01-08 00:00:00'), Timestamp('2018-01-08 00:00:00'))

Expected Output

The same as the manual operation on each bounds:

pd.Interval(year_2017.left + pd.Timedelta(days=7), year_2017.right + pd.Timedelta(days=7) ) Interval('2017-01-08', '2018-01-08', closed='right')

Output of pd.show_versions()

pandas 1.0.1

pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.7.6.final.0
python-bits : 64
OS : Linux
OS-release : 4.4.0-146-generic
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : fr_FR.UTF-8
LOCALE : fr_FR.UTF-8

pandas : 1.0.1
numpy : 1.18.1
pytz : 2019.3
dateutil : 2.8.0
pip : 19.3.1
setuptools : 41.4.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.5.0
html5lib : None
pymysql : None
psycopg2 : 2.8.4 (dt dec pq3 ext lo64)
jinja2 : 2.10.3
IPython : 7.9.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : 4.5.0
matplotlib : 3.1.2
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pytest : None
pyxlsb : None
s3fs : None
scipy : 1.3.1
sqlalchemy : 1.3.10
tables : None
tabulate : None
xarray : 0.15.0
xlrd : None
xlwt : None
xlsxwriter : None
numba : 0.46.0