Skip to content

REGR: Timestamp subtraction raises TypeError, Non informative #31774

@sbrugman

Description

@sbrugman

Code Sample

import pandas as pd
print(pd.Timestamp('2101-01-01 00:00:00') - pd.Timestamp('1688-01-01 00:00:00'))

Outputs:

TypeError: unsupported operand type(s) for -: 'Timestamp' and 'Timestamp'

Problem description

The difference between the timestamps is too large for the Timedelta object. This can be traced back to these lines:

return Timedelta(self.value - other.value)

For the example we can see that

print(pd.Timedelta(pd.Timestamp('2101-01-01 00:00:00').value - pd.Timestamp('1688-01-01 00:00:00').value))

results in
OverflowError: int too big to convert

Expected Output

Ideally, the expected output is:

150845 days 00:00:00

Note the expected output matches that of pandas 0.25.3.

Alternatively, the error message should be at least somewhat informative, for example by propagating the OverflowError (removing the try/except block from L302-305) or raising a new TypeError (similar to L296).

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.7.6.final.0
python-bits : 64
OS : Windows
OS-release : 10
machine : AMD64
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.None

pandas : 1.0.1
numpy : 1.18.0
pytz : 2019.3
dateutil : 2.8.1
pip : 19.3.1
setuptools : 42.0.2.post20191201
Cython : None
pytest : 5.3.2
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.1
IPython : 7.11.1
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : 0.3.2
gcsfs : None
lxml.etree : None
matplotlib : 3.1.2
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 0.15.1
pytables : None
pytest : 5.3.2
pyxlsb : None
s3fs : None
scipy : 1.4.1
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : 1.2.0
xlwt : None
xlsxwriter : None
numba : 0.46.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    DatetimeDatetime data dtypeRegressionFunctionality that used to work in a prior pandas version

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions