@@ -504,17 +504,11 @@ cdef class _Timestamp(ABCTimestamp):
504
504
return NotImplemented
505
505
506
506
# coerce if necessary if we are a Timestamp-like
507
- if (PyDateTime_Check(self )
508
- and (PyDateTime_Check(other) or cnp.is_datetime64_object(other))):
507
+ if PyDateTime_Check(other) or cnp.is_datetime64_object(other):
509
508
# both_timestamps is to determine whether Timedelta(self - other)
510
509
# should raise the OOB error, or fall back returning a timedelta.
511
- # TODO(cython3): clean out the bits that moved to __rsub__
512
- both_timestamps = (isinstance (other, _Timestamp) and
513
- isinstance (self , _Timestamp))
514
- if isinstance (self , _Timestamp):
515
- other = type (self )(other)
516
- else :
517
- self = type (other)(self )
510
+ both_timestamps = isinstance (other, _Timestamp)
511
+ other = type (self )(other)
518
512
519
513
if (self .tzinfo is None ) ^ (other.tzinfo is None ):
520
514
raise TypeError (
@@ -531,24 +525,18 @@ cdef class _Timestamp(ABCTimestamp):
531
525
# scalar Timestamp/datetime - Timestamp/datetime -> yields a
532
526
# Timedelta
533
527
try :
534
- res_value = self ._value- other._value
528
+ res_value = self ._value - other._value
535
529
return Timedelta._from_value_and_reso(res_value, self ._creso)
536
530
except (OverflowError , OutOfBoundsDatetime, OutOfBoundsTimedelta) as err:
537
- if isinstance (other, _Timestamp):
538
- if both_timestamps:
539
- raise OutOfBoundsDatetime(
540
- " Result is too large for pandas.Timedelta. Convert inputs "
541
- " to datetime.datetime with 'Timestamp.to_pydatetime()' "
542
- " before subtracting."
543
- ) from err
531
+ if both_timestamps:
532
+ raise OutOfBoundsDatetime(
533
+ " Result is too large for pandas.Timedelta. Convert inputs "
534
+ " to datetime.datetime with 'Timestamp.to_pydatetime()' "
535
+ " before subtracting."
536
+ ) from err
544
537
# We get here in stata tests, fall back to stdlib datetime
545
538
# method and return stdlib timedelta object
546
539
pass
547
- elif cnp.is_datetime64_object(self ):
548
- # GH#28286 cython semantics for __rsub__, `other` is actually
549
- # the Timestamp
550
- # TODO(cython3): remove this, this moved to __rsub__
551
- return type (other)(self ) - other
552
540
553
541
return NotImplemented
554
542
0 commit comments