@@ -390,6 +390,9 @@ cdef class _Timestamp(ABCTimestamp):
390
390
return NotImplemented
391
391
392
392
def __sub__ (self , other ):
393
+ # nb: counterintuitive semantics of __sub__, __rsub__ for cython < 3.x
394
+ # github.com/cython/cython/blob/2795a4/docs/src/userguide/special_methods.rst#arithmetic-methods
395
+ # GH#28286
393
396
if isinstance (self , _Timestamp) and self ._reso != NPY_FR_ns:
394
397
raise NotImplementedError (self ._reso)
395
398
@@ -445,8 +448,6 @@ cdef class _Timestamp(ABCTimestamp):
445
448
# method and return stdlib timedelta object
446
449
pass
447
450
elif is_datetime64_object(self ):
448
- # GH#28286 cython semantics for __rsub__, `other` is actually
449
- # the Timestamp
450
451
# TODO(cython3): remove this, this moved to __rsub__
451
452
return type (other)(self ) - other
452
453
@@ -459,7 +460,7 @@ cdef class _Timestamp(ABCTimestamp):
459
460
if PyDateTime_Check(other):
460
461
try :
461
462
return type (self )(other) - self
462
- except (OverflowError , OutOfBoundsDatetime) as err:
463
+ except (OverflowError , OutOfBoundsDatetime, OutOfBoundsTimedelta ) as err:
463
464
# We get here in stata tests, fall back to stdlib datetime
464
465
# method and return stdlib timedelta object
465
466
pass
0 commit comments