@@ -370,9 +370,6 @@ cdef class _Timestamp(ABCTimestamp):
370370 cdef:
371371 int64_t nanos = 0
372372
373- if isinstance (self , _Timestamp) and self ._reso != NPY_FR_ns:
374- raise NotImplementedError (self ._reso)
375-
376373 if is_any_td_scalar(other):
377374 if is_timedelta64_object(other):
378375 other_reso = get_datetime64_unit(other)
@@ -390,20 +387,31 @@ cdef class _Timestamp(ABCTimestamp):
390387 # TODO: no tests get here
391388 other = ensure_td64ns(other)
392389
390+ # TODO: what to do with mismatched resos?
393391 # TODO: disallow round_ok
394392 nanos = delta_to_nanoseconds(
395393 other, reso = self ._reso, round_ok = True
396394 )
397395 try :
398- result = type ( self )( self .value + nanos, tz = self .tzinfo)
396+ new_value = self .value + nanos
399397 except OverflowError :
400398 # Use Python ints
401399 # Hit in test_tdi_add_overflow
402- result = type (self )(int (self .value) + int (nanos), tz = self .tzinfo)
400+ new_value = int (self .value) + int (nanos)
401+
402+ try :
403+ result = type (self )._from_value_and_reso(new_value, reso = self ._reso, tz = self .tzinfo)
404+ except OverflowError as err:
405+ # TODO: don't hard-code nanosecond here
406+ raise OutOfBoundsDatetime(f" Out of bounds nanosecond timestamp: {new_value}" ) from err
407+
403408 if result is not NaT:
404409 result._set_freq(self ._freq) # avoid warning in constructor
405410 return result
406411
412+ elif isinstance (self , _Timestamp) and self ._reso != NPY_FR_ns:
413+ raise NotImplementedError (self ._reso)
414+
407415 elif is_integer_object(other):
408416 raise integer_op_not_supported(self )
409417
@@ -431,13 +439,16 @@ cdef class _Timestamp(ABCTimestamp):
431439 return NotImplemented
432440
433441 def __sub__ (self , other ):
434- if isinstance ( self , _Timestamp) and self ._reso ! = NPY_FR_ns :
435- raise NotImplementedError ( self ._reso)
442+ if other is NaT :
443+ return NaT
436444
437- if is_any_td_scalar(other) or is_integer_object(other):
445+ elif is_any_td_scalar(other) or is_integer_object(other):
438446 neg_other = - other
439447 return self + neg_other
440448
449+ elif isinstance (self , _Timestamp) and self ._reso != NPY_FR_ns:
450+ raise NotImplementedError (self ._reso)
451+
441452 elif is_array(other):
442453 if other.dtype.kind in [' i' , ' u' ]:
443454 raise integer_op_not_supported(self )
@@ -450,9 +461,6 @@ cdef class _Timestamp(ABCTimestamp):
450461 )
451462 return NotImplemented
452463
453- if other is NaT:
454- return NaT
455-
456464 # coerce if necessary if we are a Timestamp-like
457465 if (PyDateTime_Check(self )
458466 and (PyDateTime_Check(other) or is_datetime64_object(other))):
0 commit comments