Skip to content

BUG: Series inconsistent with overflow errors in Timedelta calcs #43178

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

Open
2 of 3 tasks
venaturum opened this issue Aug 23, 2021 · 4 comments
Open
2 of 3 tasks

BUG: Series inconsistent with overflow errors in Timedelta calcs #43178

venaturum opened this issue Aug 23, 2021 · 4 comments
Labels
Bug Error Reporting Incorrect or improved errors from pandas Numeric Operations Arithmetic, Comparison, and Logical operations Timedelta Timedelta data type Upstream issue Issue related to pandas dependency

Comments

@venaturum
Copy link
Contributor

venaturum commented Aug 23, 2021

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

>>> x = pd.Series([pd.Timedelta(100000, "days"), pd.Timedelta(100000, "days")])

# Results in ValueError
>>> x.sum()

# Results in OverflowError
>>> pd.Timedelta(100000, "days")*2

# Results in OverflowError
>>> x + x

# Permits overflow
>>> x*2
0   -13504 days +00:25:26.290448384
1   -13504 days +00:25:26.290448384
dtype: timedelta64[ns]

Problem description

It would seem that pandas.Series calcs with Timedeltas are inconsistent in raising overflow errors, or not.
The exact error is also inconsistent (OverflowError vs ValueError).

Expected Output

Ideally x*2 in above example raises an error, and all overflow related errors are of type OverflowError.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 5f648bf
python : 3.7.5.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19041
machine : AMD64
processor : Intel64 Family 6 Model 158 Stepping 10, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.None

pandas : 1.3.2
numpy : 1.21.2
pytz : 2021.1
dateutil : 2.8.2
pip : 19.2.3
setuptools : 41.2.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

@venaturum venaturum added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 23, 2021
@rush2406
Copy link

for x.sum() case, if you use x = x.dt.days before doing sum, it works

@venaturum
Copy link
Contributor Author

for x.sum() case, if you use x = x.dt.days before doing sum, it works

Thanks, not quite the point though.

@jbrockmendel
Copy link
Member

xref numpy/numpy#16352 (comment)

@venaturum
Copy link
Contributor Author

For anybody with similar problems playing at home, if you don't care about aligned indexes, or you can guarantee the indexes align, then the following can be used as a workaround for element-wise multiplication (which generalises the problem) between two vectors

X  # Series of timestamps
Y  # Series of floats

pd.Series([x*y for x,y in zip(X,Y)])

It will produce a series of Timedeltas and throw overflow errors if the result of any multiplication is too big

@simonjayhawkins simonjayhawkins added Upstream issue Issue related to pandas dependency Timedelta Timedelta data type Numeric Operations Arithmetic, Comparison, and Logical operations and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 26, 2021
@simonjayhawkins simonjayhawkins added this to the Contributions Welcome milestone Aug 26, 2021
@simonjayhawkins simonjayhawkins added the Error Reporting Incorrect or improved errors from pandas label Aug 26, 2021
@mroeschke mroeschke removed this from the Contributions Welcome milestone Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Error Reporting Incorrect or improved errors from pandas Numeric Operations Arithmetic, Comparison, and Logical operations Timedelta Timedelta data type Upstream issue Issue related to pandas dependency
Projects
None yet
Development

No branches or pull requests

5 participants