Skip to content

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

Merged
merged 12 commits into from
Jul 10, 2020

Conversation

jbrockmendel
Copy link
Member

  • closes #xxxx
  • tests added / passed
  • passes black pandas
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff
  • whatsnew entry

@jreback jreback added Bug Timedelta Timedelta data type labels May 29, 2020
@jreback jreback added this to the 1.1 milestone May 29, 2020
@@ -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"):
Copy link
Contributor

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

Copy link
Member Author

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

@jbrockmendel
Copy link
Member Author

@WillAyd any thoughts on what to do here? IIRC you implemented the C conversion functions for td64

@WillAyd
Copy link
Member

WillAyd commented Jun 2, 2020

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

@jbrockmendel
Copy link
Member Author

updated to give a timedelta-specific exception message

bad_val = tdmax

unit_str = arr.dtype.str.split("[")[-1][:-1]
raise OutOfBoundsDatetime(
Copy link
Contributor

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

Copy link
Contributor

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

@jbrockmendel
Copy link
Member Author

updated with requested new exception class

@jbrockmendel
Copy link
Member Author

updated+green

Copy link
Contributor

@jreback jreback left a 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

else:
bad_val = tdmax

unit_str = arr.dtype.str.split("[")[-1][:-1]
Copy link
Contributor

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]'

Copy link
Contributor

@jreback jreback left a 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.

@jbrockmendel
Copy link
Member Author

ping

@jreback jreback merged commit 283d672 into pandas-dev:master Jul 10, 2020
@jbrockmendel jbrockmendel deleted the bug-ensure_td64ns branch July 10, 2020 23:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Timedelta Timedelta data type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants