-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Raise error when datetime64 or timedelta64 values that are outside the valid range for ns precision are converted to ns precision #4454
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
Call _possibly_convert_objects on datetime64 and timedelta64 objects so that pandas raises an error if those objects are outside the valid date range for ns precision. Previously the times would be silently changed to nonsense values if they fell outside this range. Addresses GH4427.
Thanks @andrewpauling , this looks good. Could you add a test? |
Hi @max-sixty, I have just added what I hope is a good test, I haven't written one before, but tried to base it on others in the test_variable file |
It looks great! I made one suggestion. Any thoughts from others? |
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.
Nice! Could you also add a similar test for timedelta64
data?
Hi @spencerkclark, I have been trying to work on a test for timedelta64 data but I don't think I understand timedelta data very well. I can't seem to come up with an example that raises an |
You're absolutely right @andrewpauling -- pandas currently doesn't seem to have overflow protection in the case of casting For now maybe you can add the test and attach an expected failure decorator to it? In researching this, I came across numpy/numpy#16352; if that eventually gets addressed this might all be moot. |
Thanks @spencerkclark, I have added a test with the decorator you mentioned and edited the formatting in the whats-new file as above. Hopefully it should be good now. |
Excellent, thanks @andrewpauling ! LGTM |
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.
Thanks @andrewpauling! Sorry for taking a bit to re-review; it looks like there's now a minor merge conflict in the what's new page. Once that's sorted out, I think this should be good to go.
update from remote
…array into fix_dt64_casting update from origin
Great, let's merge on green! |
Cool! Thank you all for your help. |
Thanks again @andrewpauling! |
Thanks a lot @andrewpauling ! |
Use _possibly_convert_obhects to raise an error when converting datetime64 or timedelta64 objects that are in some units other than ns to ns as per pandas requirements, resulting in dates outside the valid range for ns precision being silently changed to incorrect values.
isort . && black . && mypy . && flake8
whats-new.rst