Skip to content
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

Unable to add Timedelta to a Timestamp Interval #32023

Closed
oarcher opened this issue Feb 15, 2020 · 1 comment · Fixed by #32107
Closed

Unable to add Timedelta to a Timestamp Interval #32023

oarcher opened this issue Feb 15, 2020 · 1 comment · Fixed by #32107
Labels
Bug Interval Interval data type
Milestone

Comments

@oarcher
Copy link

oarcher commented Feb 15, 2020

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 "<stdin>", line 1, in <module>
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

@dsaxton
Copy link
Member

dsaxton commented Feb 19, 2020

Thanks for the report, looks like a bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Interval Interval data type
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants