-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Better error message for OOB result #32499
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
Changes from 4 commits
15eb9cb
bb283d3
815050f
6817c45
d4aa8e8
b748784
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -287,9 +287,13 @@ cdef class _Timestamp(datetime): | |
if (PyDateTime_Check(self) | ||
and (PyDateTime_Check(other) or is_datetime64_object(other))): | ||
if isinstance(self, _Timestamp): | ||
other = type(self)(other) | ||
both_timestamps = isinstance(other, _Timestamp) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jbrockmendel can you take another look when you get a chance? Needed to change some things around to ensure that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this looks like you're avoiding re-calling the constructor if we already have a Timestamp. Is that necessary? The constructor was recently optimized for the already-Timestamp case There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. never mind, i get it now There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe add a comment to the effect of "we need to know if we started with both-Timestamps to determine whether to raise on Overflow, see GH#..." |
||
if not both_timestamps: | ||
other = type(self)(other) | ||
else: | ||
self = type(other)(self) | ||
both_timestamps = isinstance(self, _Timestamp) | ||
if not both_timestamps: | ||
self = type(other)(self) | ||
|
||
# validate tz's | ||
if not tz_compare(self.tzinfo, other.tzinfo): | ||
|
@@ -301,7 +305,14 @@ cdef class _Timestamp(datetime): | |
from pandas._libs.tslibs.timedeltas import Timedelta | ||
try: | ||
return Timedelta(self.value - other.value) | ||
except (OverflowError, OutOfBoundsDatetime): | ||
except (OverflowError, OutOfBoundsDatetime) as err: | ||
if isinstance(other, _Timestamp): | ||
if both_timestamps: | ||
raise OutOfBoundsDatetime( | ||
"Result is too large for pandas.Timedelta. Convert inputs " | ||
"to datetime.datetime with 'Timestamp.to_pydatetime()' " | ||
"before subtracting." | ||
) from err | ||
pass | ||
elif is_datetime64_object(self): | ||
# GH#28286 cython semantics for __rsub__, `other` is actually | ||
|
Uh oh!
There was an error while loading. Please reload this page.