@@ -119,8 +119,6 @@ def ints_to_pytimedelta(int64_t[:] arr, box=False):
119
119
# ----------------------------------------------------------------------
120
120
121
121
cpdef int64_t delta_to_nanoseconds(delta) except ? - 1 :
122
- if util.is_array(delta):
123
- return delta.astype(' m8[ns]' ).astype(' int64' )
124
122
if hasattr (delta, ' nanos' ):
125
123
return delta.nanos
126
124
if hasattr (delta, ' delta' ):
@@ -129,10 +127,12 @@ cpdef int64_t delta_to_nanoseconds(delta) except? -1:
129
127
return delta.astype(" timedelta64[ns]" ).item()
130
128
if is_integer_object(delta):
131
129
return delta
130
+ if PyDelta_Check(delta):
131
+ return (delta.days * 24 * 60 * 60 * 1000000 +
132
+ delta.seconds * 1000000 +
133
+ delta.microseconds) * 1000
132
134
133
- return (delta.days * 24 * 60 * 60 * 1000000 +
134
- delta.seconds * 1000000 +
135
- delta.microseconds) * 1000
135
+ raise TypeError (type (delta))
136
136
137
137
138
138
cpdef convert_to_timedelta64(object ts, object unit):
@@ -198,7 +198,7 @@ cpdef convert_to_timedelta64(object ts, object unit):
198
198
return ts.astype(' timedelta64[ns]' )
199
199
200
200
201
- cpdef array_to_timedelta64(object [:] values, unit = ' ns' , errors = ' raise' ):
201
+ def array_to_timedelta64 (object[:] values , unit = ' ns' , errors = ' raise' ):
202
202
"""
203
203
Convert an ndarray to an array of timedeltas. If errors == 'coerce',
204
204
coerce non-convertible objects to NaT. Otherwise, raise.
@@ -235,7 +235,7 @@ cpdef array_to_timedelta64(object[:] values, unit='ns', errors='raise'):
235
235
return iresult.base # .base to access underlying np.ndarray
236
236
237
237
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 :
239
239
""" return a casting of the unit represented to nanoseconds
240
240
round the fractional part of a float to our precision, p """
241
241
cdef:
0 commit comments