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
DOC: undocumented behavior for converting month timedelta64 to days #26121
Comments
This is happening because numpy defaults to "unsafe" casting in
According to the source code, this is the correct result averaged over a 400 year leap-year cycle: numpy/numpy/_core/src/multiarray/datetime.c Lines 1093 to 1096 in 34fa608
A PR documenting these rules would be very welcome. |
Hi, is this issue still open. Please, can I have the opportunity to work on this issue. |
We don’t claim issues in numpy, please go ahead, in the future just check if anyone already has a PR open for an issue |
Hi @ngoldbaum , |
Issue with current documentation:
I have three syntaxes that attempt to convert a timedelta64 in month into days. As is well explained in the documentation:
https://numpy.org/doc/stable/reference/arrays.datetime.html#arrays-datetime
this is not possible because we do not know how many days a month holds:
np.timedelta64(1, 'M') / np.timedelta64(1, 'D')
Cannot get a common metadata divisor for Numpy datetime metadata [M] and [D] because they have incompatible nonlinear base time units.
timedelta64(timedelta64(1, 'M'), 'D')
Cannot cast NumPy timedelta64 scalar from metadata [M] to [D] according to the rule 'same_kind'
but this yields:
timedelta64(1, 'M').astype(timedelta64(1, 'D'))
numpy.timedelta64(30,'D')
I am surprised that there is no error in the latter case but I am mostly interested to find out which rules are used to determine 30 in this case. For example:
timedelta64(3, 'M').astype(timedelta64(1, 'D'))
numpy.timedelta64(91,'D')
which indicates to me that there is some kind of heuristics used but I have not been able to find its documentation.
Thank you for your help,
Sacha
Idea or request for content:
No response
The text was updated successfully, but these errors were encountered: