Skip to content

Commit 7a7418a

Browse files
handle older and newer cython semantics
1 parent a72d4e0 commit 7a7418a

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

pandas/_libs/tslibs/timestamps.pyx

+4-3
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,9 @@ cdef class _Timestamp(ABCTimestamp):
390390
return NotImplemented
391391

392392
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
393396
if isinstance(self, _Timestamp) and self._reso != NPY_FR_ns:
394397
raise NotImplementedError(self._reso)
395398

@@ -445,8 +448,6 @@ cdef class _Timestamp(ABCTimestamp):
445448
# method and return stdlib timedelta object
446449
pass
447450
elif is_datetime64_object(self):
448-
# GH#28286 cython semantics for __rsub__, `other` is actually
449-
# the Timestamp
450451
# TODO(cython3): remove this, this moved to __rsub__
451452
return type(other)(self) - other
452453

@@ -459,7 +460,7 @@ cdef class _Timestamp(ABCTimestamp):
459460
if PyDateTime_Check(other):
460461
try:
461462
return type(self)(other) - self
462-
except (OverflowError, OutOfBoundsDatetime) as err:
463+
except (OverflowError, OutOfBoundsDatetime, OutOfBoundsTimedelta) as err:
463464
# We get here in stata tests, fall back to stdlib datetime
464465
# method and return stdlib timedelta object
465466
pass

0 commit comments

Comments
 (0)