Skip to content

BUG: catch overflow in timestamp + offset operations #15126

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
wants to merge 1 commit into from

Conversation

jreback
Copy link
Contributor

@jreback jreback commented Jan 13, 2017

@jreback jreback added Bug Datetime Datetime data dtype labels Jan 13, 2017
@jreback jreback added this to the 0.20.0 milestone Jan 13, 2017
@@ -1220,7 +1220,10 @@ cdef class _Timestamp(datetime):
return Timestamp((self.freq * other).apply(self), freq=self.freq)

elif isinstance(other, timedelta) or hasattr(other, 'delta'):
nanos = _delta_to_nanoseconds(other)
try:
Copy link
Contributor Author

@jreback jreback Jan 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @shoyer
since IIRC you have some expertise doing this.

I could not get this to raise the exception at all (from cython), rather it always wanted to simply call __radd__. The only way is to return NotImplemented.

any better way to do this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cython really doesn't let you raise any errors from __add__ without calling __radd__ on the other object? That is surprising -- and disappointing!

It is true that Cython will use __add__ for both Python's __add__ and __radd__, so self in this method may not be a Timestamp instance:
http://cython.readthedocs.io/en/latest/src/userguide/special_methods.html#arithmetic-methods

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok I sorted. Its very odd that it doesn't raise the actual exception.

@codecov-io
Copy link

codecov-io commented Jan 14, 2017

Current coverage is 85.53% (diff: 100%)

Merging #15126 into master will increase coverage by <.01%

@@             master     #15126   diff @@
==========================================
  Files           145        145          
  Lines         51274      51281     +7   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits          43856      43865     +9   
+ Misses         7418       7416     -2   
  Partials          0          0          

Powered by Codecov. Last update e6a3c35...923eaa2

@@ -2748,14 +2751,20 @@ def nanos(self):

def apply(self, other):
# Timestamp can handle tz and nano sec, thus no need to use apply_wraps
if isinstance(other, (datetime, np.datetime64, date)):
if isinstance(other, Timestamp):
result = other.__add__(self)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you really need to call __add__ here rather than using +?

Generally calling double-underscore methods directly is an anti-pattern, so if so this definitely deserves a comment to explain.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a comment. The + causes it to segfault. I think its because of a fast-path in the interpreter, or maybe a cython bug. If there is an exception during the the operation. Then we compound this by trying the reversed ops in .apply and the cycle repeats. But I think its too hard (maybe impossible) to change this.

@jreback jreback closed this in 7892077 Jan 14, 2017
AnkurDedania pushed a commit to AnkurDedania/pandas that referenced this pull request Mar 21, 2017
xref statsmodels/statsmodels#3374

Author: Jeff Reback <[email protected]>

Closes pandas-dev#15126 from jreback/inc and squashes the following commits:

923eaa2 [Jeff Reback] BUG: catch overflow in timestamp + offset operations
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 this pull request may close these issues.

3 participants