@@ -119,8 +119,6 @@ def ints_to_pytimedelta(int64_t[:] arr, box=False):
119119# ----------------------------------------------------------------------
120120
121121cpdef int64_t delta_to_nanoseconds(delta) except ? - 1 :
122- if util.is_array(delta):
123- return delta.astype(' m8[ns]' ).astype(' int64' )
124122 if hasattr (delta, ' nanos' ):
125123 return delta.nanos
126124 if hasattr (delta, ' delta' ):
@@ -129,10 +127,12 @@ cpdef int64_t delta_to_nanoseconds(delta) except? -1:
129127 return delta.astype(" timedelta64[ns]" ).item()
130128 if is_integer_object(delta):
131129 return delta
130+ if PyDelta_Check(delta):
131+ return (delta.days * 24 * 60 * 60 * 1000000 +
132+ delta.seconds * 1000000 +
133+ delta.microseconds) * 1000
132134
133- return (delta.days * 24 * 60 * 60 * 1000000 +
134- delta.seconds * 1000000 +
135- delta.microseconds) * 1000
135+ raise TypeError (type (delta))
136136
137137
138138cpdef convert_to_timedelta64(object ts, object unit):
@@ -198,7 +198,7 @@ cpdef convert_to_timedelta64(object ts, object unit):
198198 return ts.astype(' timedelta64[ns]' )
199199
200200
201- cpdef array_to_timedelta64(object [:] values, unit = ' ns' , errors = ' raise' ):
201+ def array_to_timedelta64 (object[:] values , unit = ' ns' , errors = ' raise' ):
202202 """
203203 Convert an ndarray to an array of timedeltas. If errors == 'coerce',
204204 coerce non-convertible objects to NaT. Otherwise, raise.
@@ -235,7 +235,7 @@ cpdef array_to_timedelta64(object[:] values, unit='ns', errors='raise'):
235235 return iresult.base # .base to access underlying np.ndarray
236236
237237
238- cpdef inline int64_t cast_from_unit(object ts, object unit) except ? - 1 :
238+ cdef inline int64_t cast_from_unit(object ts, object unit) except ? - 1 :
239239 """ return a casting of the unit represented to nanoseconds
240240 round the fractional part of a float to our precision, p """
241241 cdef:
0 commit comments