You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
NumPy does have a code path that goes via the datetimestruct and back (for complicated non-linear time casts), but it is only used for "nonlinear" translation.
It might be nice to try and see if we can just adjust the fast path to fix these, rather do the full, slow path?
Plus, timedelta's have the same problem, and those never use the datetimestruct!
OK, so for datetimes, we know that num == 1 || denom == 1, because if that is not the case we have a "nonlinear" transform (months or years are involved, which we do not define a clear duration for).
For that path, I think simply reordering the calculation using that knowledge seems an easy fix for datetime.
For timedelta, going via the datetimestruct would seem to subtly change behavior, because currently it uses the 400 year average duration for years and months? @jbrockmendel am I understanding it right that the pandas code effectively pretends the timedelta is a datetime for the conversion?
In general, we could throw in overflow detection for the multiplication and return NaT with a warning...
(I will note that I suspect the whole thing is more far more complicated than NumPy is making it to begin with... If we are aiming for perfect time handling.)
am I understanding it right that the pandas code effectively pretends the timedelta is a datetime for the conversion?
Yes.
For timedelta, going via the datetimestruct would seem to subtly change behavior, because currently it uses the 400 year average duration for years and months?
Y and M are kind of a mess in pandas, not sure how much of that is shared with numpy vs introduced in precision_from_unit.
I think that the last part is shared. Did pandas remove support for those timedelta's completely (my pandas version complains: ValueError: Units 'M', 'Y', and 'y' are no longer supported, as they do not represent unambiguous timedelta values durations.)?
Maybe NumPy should consider deprecating these "nonlinear" casts for timedelta?
Where did you read about such changes on pandas?
I've noticed a weird behavior on a old script after updating some libs but couldn't confirm such change.
Activity
seberg commentedon Sep 28, 2022
Interesting, the reason is that we are using this to do the calculation when the value is
< 0:(missing first bracket so that grepping for all occurrences works). In this case
numis 1 anddenomis 60.This is supposed to get the rounding right, which I guess is probably right? But the temporary overflows. Maybe
(dt * num + 1) / denom - 1would help?jbrockmendel commentedon Sep 29, 2022
That's plausible. If viable my solution would be to upstream astype_overflowsafe
seberg commentedon Sep 29, 2022
NumPy does have a code path that goes via the datetimestruct and back (for complicated non-linear time casts), but it is only used for "nonlinear" translation.
It might be nice to try and see if we can just adjust the fast path to fix these, rather do the full, slow path?
Plus, timedelta's have the same problem, and those never use the datetimestruct!
seberg commentedon Sep 30, 2022
OK, so for datetimes, we know that
num == 1 || denom == 1, because if that is not the case we have a "nonlinear" transform (months or years are involved, which we do not define a clear duration for).For that path, I think simply reordering the calculation using that knowledge seems an easy fix for
datetime.For timedelta, going via the datetimestruct would seem to subtly change behavior, because currently it uses the 400 year average duration for years and months?
@jbrockmendel am I understanding it right that the pandas code effectively pretends the timedelta is a datetime for the conversion?
In general, we could throw in overflow detection for the multiplication and return NaT with a warning...
(I will note that I suspect the whole thing is more far more complicated than NumPy is making it to begin with... If we are aiming for perfect time handling.)
jbrockmendel commentedon Oct 3, 2022
Yes.
Y and M are kind of a mess in pandas, not sure how much of that is shared with numpy vs introduced in precision_from_unit.
seberg commentedon Oct 4, 2022
I think that the last part is shared. Did pandas remove support for those timedelta's completely (my pandas version complains:
ValueError: Units 'M', 'Y', and 'y' are no longer supported, as they do not represent unambiguous timedelta values durations.)?Maybe NumPy should consider deprecating these "nonlinear" casts for timedelta?
frbelotto commentedon Oct 4, 2022
Where did you read about such changes on pandas?
I've noticed a weird behavior on a old script after updating some libs but couldn't confirm such change.
seberg commentedon Oct 4, 2022
TST: add targeted tests for numpygh-16352 and numpygh-22346