Skip to content

Commit f132c90

Browse files
jbrockmendelrhshadrach
authored andcommitted
CLN: remove _typ checks in Timestamp methods (pandas-dev#34024)
1 parent 051723f commit f132c90

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

pandas/_libs/tslibs/c_timestamp.pyx

+6-13
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,11 @@ cdef class _Timestamp(datetime):
251251
# delta --> offsets.Tick
252252
# logic copied from delta_to_nanoseconds to prevent circular import
253253
if hasattr(other, 'nanos'):
254+
# Tick
254255
nanos = other.nanos
255256
elif hasattr(other, 'delta'):
256-
nanos = other.delta
257+
# pd.Timedelta
258+
nanos = other.value
257259
elif PyDelta_Check(other):
258260
nanos = (other.days * 24 * 60 * 60 * 1000000 +
259261
other.seconds * 1000000 +
@@ -273,15 +275,7 @@ cdef class _Timestamp(datetime):
273275
dtype=object,
274276
)
275277

276-
# index/series like
277-
elif hasattr(other, '_typ'):
278-
return NotImplemented
279-
280-
result = datetime.__add__(self, other)
281-
if PyDateTime_Check(result):
282-
result = type(self)(result)
283-
result.nanosecond = self.nanosecond
284-
return result
278+
return NotImplemented
285279

286280
def __sub__(self, other):
287281

@@ -301,9 +295,6 @@ cdef class _Timestamp(datetime):
301295
[self - other[n] for n in range(len(other))],
302296
dtype=object,
303297
)
304-
305-
typ = getattr(other, '_typ', None)
306-
if typ is not None:
307298
return NotImplemented
308299

309300
if other is NaT:
@@ -339,6 +330,8 @@ cdef class _Timestamp(datetime):
339330
"to datetime.datetime with 'Timestamp.to_pydatetime()' "
340331
"before subtracting."
341332
) from err
333+
# We get here in stata tests, fall back to stdlib datetime
334+
# method and return stdlib timedelta object
342335
pass
343336
elif is_datetime64_object(self):
344337
# GH#28286 cython semantics for __rsub__, `other` is actually

0 commit comments

Comments
 (0)