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
{{ message }}
Repository navigation
ENH: datetime/timedelta arithmetic with python datetime/timedelta scalars #30985
I have noticed some inconsistency with how numpy handles datetime and timedelta arithmetic, compared to regular numeric types. With regular numerical types, addition between numpy scalars and corresponding python scalars always yields numpy scalars:
changed the title [-]ENH: datetime/timedelta arithmetic with python datetime/tiemdelta scalars[/-][+]ENH: datetime/timedelta arithmetic with python datetime/timedelta scalars[/+]on Mar 10, 2026
FWIW, I could imagine this is fine, all of this behavior comes down to np.asarray(dt.timedelta(seconds=5)) not picking an m8[ns] or similar default.
Is that something one can decide on? Because if, things would be a lot more straight-forward.
Without that, I am afraid, implementing np_timedelta + python_timdelta will leave the array paths still dangling. gh-28596 would fix that partially, the other approach might be more promotion specialization, but I don't really like that thought.
(In fact gh-28596 is interesting, in that I am not sure if it proposed to add the scalar operations, since without that mixing fails.)
Activity
[-]ENH: datetime/timedelta arithmetic with python datetime/tiemdelta scalars[/-][+]ENH: datetime/timedelta arithmetic with python datetime/timedelta scalars[/+]ngoldbaum commentedon Mar 10, 2026
I'm not sure how load-bearing this behavior is in Pandas, but also I'm not sure how you could check that without making the change.
seberg commentedon Mar 11, 2026
FWIW, I could imagine this is fine, all of this behavior comes down to
np.asarray(dt.timedelta(seconds=5))not picking anm8[ns]or similar default.Is that something one can decide on? Because if, things would be a lot more straight-forward.
Without that, I am afraid, implementing
np_timedelta + python_timdeltawill leave the array paths still dangling.gh-28596 would fix that partially, the other approach might be more promotion specialization, but I don't really like that thought.
(In fact gh-28596 is interesting, in that I am not sure if it proposed to add the scalar operations, since without that mixing fails.)
jbrockmendel commentedon Mar 28, 2026
Not at all. We wrap dt64/td64 arrays/scalars and use our own code specifically because of the weird behaviors numpy has.