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
For a negative timedelta64[ns] of 42 nanoseconds DataArray.dt.seconds returned a non-zero value (the returned value was 86399). When I pass in a positive 42 nanosecond timedelta64[ns] with the the TimeDeltaAccessor correctly returns zero. I would have expected both assertions in the example below to have passed, but the second fails. This seems to be a general issue with negative timedelta64[ns].
I think the issue arises because pandas turns the numpy timedelta64 into a "minus one day plus a time". This actually does have a number of "seconds" in it, but the "total_seconds" has the expected value:
Maybe we should handle this as a special case by taking the absolute value before passing the values to pandas (and then applying the original sign again afterwards)?
What happened:
For a negative
timedelta64[ns]
of 42 nanosecondsDataArray.dt.seconds
returned a non-zero value (the returned value was86399
). When I pass in a positive 42 nanosecondtimedelta64[ns]
with the the TimeDeltaAccessor correctly returns zero. I would have expected both assertions in the example below to have passed, but the second fails. This seems to be a general issue with negativetimedelta64[ns]
.What you expected to happen:
Minimal Complete Verifiable Example:
Anything else we need to know?:
I've narrowed this down to the call to
pd.Series(values.ravel())
inxarray.core.accessor_dt._access_through_series
:I think the issue arises because pandas turns the numpy timedelta64 into a "minus one day plus a time". This actually does have a number of "seconds" in it, but the "total_seconds" has the expected value:
Which would correctly round to zero.
I don't think the issue is in pandas, although the output from pandas is counter-intuitive:
Maybe we should handle this as a special case by taking the absolute value before passing the values to pandas (and then applying the original sign again afterwards)?
Environment:
Output of xr.show_versions()
The text was updated successfully, but these errors were encountered: