Skip to content

BUG: overflow in Timedelta arithmetic #17637

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

Closed
jreback opened this issue Sep 23, 2017 · 5 comments · Fixed by #17640
Closed

BUG: overflow in Timedelta arithmetic #17637

jreback opened this issue Sep 23, 2017 · 5 comments · Fixed by #17640
Labels
Bug Datetime Datetime data dtype
Milestone

Comments

@jreback
Copy link
Contributor

jreback commented Sep 23, 2017

xref #17318 (comment)

This is not behaving on master, started after: b59f107

In [1]: date_range(start='1/1/1700', freq='B', periods=100000)
---------------------------------------------------------------------------
OverflowError                             Traceback (most recent call last)
OverflowError: Python int too large to convert to C long
Exception ignored in: 'pandas._libs.tslib._delta_to_nanoseconds'
OverflowError: Python int too large to convert to C long
Out[1]: DatetimeIndex(['1700-01-01', '1700-01-04', '1700-01-05', '1700-01-06', '1700-01-07'], dtype='datetime64[ns]', freq='B')

@jreback jreback added this to the 0.21.0 milestone Sep 23, 2017
@jreback jreback mentioned this issue Sep 23, 2017
1 task
@jbrockmendel
Copy link
Member

A sufficient condition to fix this particular error:

  1. Revert cpdef int64_t _delta_to_nanoseconds(delta): --> def _delta_to_nanoseconds(delta): (with or without cpdef, shouldn't matter)
  2. In _Timestamp.__add__ don't declare a type for nanos
  3. Open an issue for a longer-term solution.

@jreback
Copy link
Contributor Author

jreback commented Sep 23, 2017

@jbrockmendel its actually much simpler than that.

  1. there isn't really a good long term soln. well there is, multi-unit timedelta types, but that is quite a lot of work and will have to wait for pandas2.

jreback added a commit to jreback/pandas that referenced this issue Sep 23, 2017
@jreback
Copy link
Contributor Author

jreback commented Sep 23, 2017

  1. In _Timestamp.add don't declare a type for nanos

not realistic, you want to declare types for things as you actually want the overflow

@jreback jreback changed the title BUG: overflow in Timestamp.replace BUG: overflow in Timedelta arithmetic Sep 23, 2017
@jbrockmendel
Copy link
Member

there isn't really a good long term soln. well there is, multi-unit timedelta types, but that is quite a lot of work and will have to wait for pandas2.

Yah. I've spent enough time with np_datetime.c to know that numpy has implemented multi-unit datetime64, haven't looked at their timedelta64 implementation that closely. I'll check if they've got anything that can be adapted.

@jreback
Copy link
Contributor Author

jreback commented Sep 23, 2017

There are actually 2 issues:

  1. support multi-units (e.g. [s]) based Timedeltas.
  2. properly cast when overflowing (then cast back)

these are both useful but non-trivial.

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

Successfully merging a pull request may close this issue.

2 participants