-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: ensure_timedelta64ns overflows #34448
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
Conversation
@@ -80,6 +86,12 @@ def test_ensure_datetime64ns_bigendian(): | |||
tm.assert_numpy_array_equal(result, expected) | |||
|
|||
|
|||
def test_ensure_timedelta64ns_overflows(): | |||
arr = np.arange(10).astype("m8[Y]") * 100 | |||
with pytest.raises(OutOfBoundsDatetime, match="Out of bounds"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the wrong type that is raises for this dtypes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yah, im not too bothered by the exception type, but the exception message is going to have a datetime string in it that wont be helpful. giving this some thought
@WillAyd any thoughts on what to do here? IIRC you implemented the C conversion functions for td64 |
So IIUC you are concerned about the value shown in the error message right? I did implement the time delta->ISO string methods which could use here, though not sure if necessary |
updated to give a timedelta-specific exception message |
pandas/_libs/tslibs/conversion.pyx
Outdated
bad_val = tdmax | ||
|
||
unit_str = arr.dtype.str.split("[")[-1][:-1] | ||
raise OutOfBoundsDatetime( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we just create OutOfBoundsTimedelta
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think if we create an OOBTimedelta exception would be ok ith this change
updated with requested new exception class |
updated+green |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all looks good, small comment
pandas/_libs/tslibs/conversion.pyx
Outdated
else: | ||
bad_val = tdmax | ||
|
||
unit_str = arr.dtype.str.split("[")[-1][:-1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems fragile, can you just report it entirely:
In [39]: np.dtype('m8[ms]').name
Out[39]: 'timedelta64[ms]'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm. ping on green.
ping |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff