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
i.e. Series[timedelta64] treats pd.NaT as a timedelta, while TimedeltaIndex treats pd.NaT as a datetime (in a way that makes sense for addition but not for subtraction).
Expected Behavior
Internal consistency in the sense that:
For tdi - pd.NaT it only makes sense for the result to be timedelta64, so the TimedeltaIndex behavior is wrong.
For tdi + pd.NaT a reasonable argument can be made for the result being either timedelta64 or datetime64. Returning timedelta64 maintains consistency with TimedeltaIndex.__sub__, while datetime64 maintains consistency with TimedeltaIndex.__radd__. All in all I think keeping addition commutative is the more important of the two.
The text was updated successfully, but these errors were encountered:
The subtraction is clearly wrong as is, but if the default is to view NaT as a datetime, then pd.NaT + tdi should be a DatetimeIndex, in which case tdi + pd.NaT probably should too.
I've implemented the change in #19139, but really want to make sure we're on the same page that there is no way to be entirely internally consistent because pd.NaT is quacks like either a datetime or a timedelta.
Analogous to (#18808)
Adapted from
tests.indexes.timedeltas.test_arithmetic.TestTimedeltaIndexArithmetic.test_timedelta_ops_with_missing_values
i.e.
Series[timedelta64]
treatspd.NaT
as atimedelta
, whileTimedeltaIndex
treatspd.NaT
as adatetime
(in a way that makes sense for addition but not for subtraction).Expected Behavior
Internal consistency in the sense that:
For
tdi - pd.NaT
it only makes sense for the result to betimedelta64
, so theTimedeltaIndex
behavior is wrong.For
tdi + pd.NaT
a reasonable argument can be made for the result being eithertimedelta64
ordatetime64
. Returning timedelta64 maintains consistency withTimedeltaIndex.__sub__
, whiledatetime64
maintains consistency withTimedeltaIndex.__radd__
. All in all I think keeping addition commutative is the more important of the two.The text was updated successfully, but these errors were encountered: