@@ -91,7 +91,7 @@ def ensure_datetime64ns(ndarray arr, copy=True):
9191 """
9292 cdef:
9393 Py_ssize_t i, n = arr.size
94- ndarray[ int64_t] ivalues, iresult
94+ int64_t[: ] ivalues, iresult
9595 NPY_DATETIMEUNIT unit
9696 npy_datetimestruct dts
9797
@@ -139,7 +139,7 @@ def ensure_timedelta64ns(ndarray arr, copy=True):
139139 return arr.astype(TD_DTYPE, copy = copy)
140140
141141
142- def datetime_to_datetime64 (ndarray[ object] values ):
142+ def datetime_to_datetime64 (object[: ] values ):
143143 """
144144 Convert ndarray of datetime-like objects to int64 array representing
145145 nanosecond timestamps.
@@ -156,7 +156,7 @@ def datetime_to_datetime64(ndarray[object] values):
156156 cdef:
157157 Py_ssize_t i, n = len (values)
158158 object val, inferred_tz = None
159- ndarray[ int64_t] iresult
159+ int64_t[: ] iresult
160160 npy_datetimestruct dts
161161 _TSObject _ts
162162
@@ -525,7 +525,8 @@ cdef inline void localize_tso(_TSObject obj, tzinfo tz):
525525 Sets obj.tzinfo inplace, alters obj.dts inplace.
526526 """
527527 cdef:
528- ndarray[int64_t] trans, deltas
528+ ndarray[int64_t] trans
529+ int64_t[:] deltas
529530 int64_t local_val
530531 Py_ssize_t pos
531532
@@ -631,15 +632,16 @@ cdef inline int64_t[:] _tz_convert_dst(ndarray[int64_t] values, tzinfo tz,
631632 cdef:
632633 Py_ssize_t n = len (values)
633634 Py_ssize_t i, j, pos
634- ndarray[int64_t] result = np.empty(n, dtype = np.int64)
635- ndarray[int64_t] tt, trans, deltas
636- ndarray[Py_ssize_t] posn
635+ int64_t[:] result = np.empty(n, dtype = np.int64)
636+ ndarray[int64_t] tt, trans
637+ int64_t[:] deltas
638+ Py_ssize_t[:] posn
637639 int64_t v
638640
639641 trans, deltas, typ = get_dst_info(tz)
640642 if not to_utc:
641643 # We add `offset` below instead of subtracting it
642- deltas = - 1 * deltas
644+ deltas = - 1 * np.array( deltas, dtype = ' i8 ' )
643645
644646 tt = values[values != NPY_NAT]
645647 if not len (tt):
@@ -728,7 +730,7 @@ cpdef int64_t tz_convert_single(int64_t val, object tz1, object tz2):
728730 converted: int64
729731 """
730732 cdef:
731- ndarray[ int64_t] trans, deltas
733+ int64_t[:] deltas
732734 Py_ssize_t pos
733735 int64_t v, offset, utc_date
734736 npy_datetimestruct dts
@@ -756,7 +758,7 @@ cpdef int64_t tz_convert_single(int64_t val, object tz1, object tz2):
756758 else :
757759 # Convert UTC to other timezone
758760 arr = np.array([utc_date])
759- # Note: at least with cython 0.28.3, doing a looking `[0]` in the next
761+ # Note: at least with cython 0.28.3, doing a lookup `[0]` in the next
760762 # line is sensitive to the declared return type of _tz_convert_dst;
761763 # if it is declared as returning ndarray[int64_t], a compile-time error
762764 # is raised.
@@ -781,10 +783,9 @@ def tz_convert(ndarray[int64_t] vals, object tz1, object tz2):
781783 """
782784
783785 cdef:
784- ndarray[int64_t] utc_dates, tt, result, trans, deltas
786+ ndarray[int64_t] utc_dates, result
785787 Py_ssize_t i, j, pos, n = len (vals)
786- int64_t v, offset, delta
787- npy_datetimestruct dts
788+ int64_t v
788789
789790 if len (vals) == 0 :
790791 return np.array([], dtype = np.int64)
@@ -843,7 +844,8 @@ def tz_localize_to_utc(ndarray[int64_t] vals, object tz, object ambiguous=None,
843844 localized : ndarray[int64_t]
844845 """
845846 cdef:
846- ndarray[int64_t] trans, deltas, idx_shifted
847+ ndarray[int64_t] trans
848+ int64_t[:] deltas, idx_shifted
847849 ndarray ambiguous_array
848850 Py_ssize_t i, idx, pos, ntrans, n = len (vals)
849851 int64_t * tdata
@@ -1069,7 +1071,7 @@ def normalize_date(object dt):
10691071
10701072@ cython.wraparound (False )
10711073@ cython.boundscheck (False )
1072- def normalize_i8_timestamps (ndarray[ int64_t] stamps , tz = None ):
1074+ def normalize_i8_timestamps (int64_t[: ] stamps , tz = None ):
10731075 """
10741076 Normalize each of the (nanosecond) timestamps in the given array by
10751077 rounding down to the beginning of the day (i.e. midnight). If `tz`
@@ -1087,7 +1089,7 @@ def normalize_i8_timestamps(ndarray[int64_t] stamps, tz=None):
10871089 cdef:
10881090 Py_ssize_t i, n = len (stamps)
10891091 npy_datetimestruct dts
1090- ndarray[ int64_t] result = np.empty(n, dtype = np.int64)
1092+ int64_t[: ] result = np.empty(n, dtype = np.int64)
10911093
10921094 if tz is not None :
10931095 tz = maybe_get_tz(tz)
@@ -1101,12 +1103,12 @@ def normalize_i8_timestamps(ndarray[int64_t] stamps, tz=None):
11011103 dt64_to_dtstruct(stamps[i], & dts)
11021104 result[i] = _normalized_stamp(& dts)
11031105
1104- return result
1106+ return result.base # .base to access underlying np.ndarray
11051107
11061108
11071109@ cython.wraparound (False )
11081110@ cython.boundscheck (False )
1109- cdef ndarray[ int64_t] _normalize_local(ndarray[ int64_t] stamps, object tz):
1111+ cdef int64_t[: ] _normalize_local(int64_t[: ] stamps, object tz):
11101112 """
11111113 Normalize each of the (nanosecond) timestamps in the given array by
11121114 rounding down to the beginning of the day (i.e. midnight) for the
@@ -1123,8 +1125,9 @@ cdef ndarray[int64_t] _normalize_local(ndarray[int64_t] stamps, object tz):
11231125 """
11241126 cdef:
11251127 Py_ssize_t n = len (stamps)
1126- ndarray[int64_t] result = np.empty(n, dtype = np.int64)
1127- ndarray[int64_t] trans, deltas
1128+ int64_t[:] result = np.empty(n, dtype = np.int64)
1129+ ndarray[int64_t] trans
1130+ int64_t[:] deltas
11281131 Py_ssize_t[:] pos
11291132 npy_datetimestruct dts
11301133 int64_t delta
@@ -1190,7 +1193,7 @@ cdef inline int64_t _normalized_stamp(npy_datetimestruct *dts) nogil:
11901193 return dtstruct_to_dt64(dts)
11911194
11921195
1193- def is_date_array_normalized (ndarray[ int64_t] stamps , tz = None ):
1196+ def is_date_array_normalized (int64_t[: ] stamps , tz = None ):
11941197 """
11951198 Check if all of the given (nanosecond) timestamps are normalized to
11961199 midnight, i.e. hour == minute == second == 0. If the optional timezone
@@ -1206,8 +1209,9 @@ def is_date_array_normalized(ndarray[int64_t] stamps, tz=None):
12061209 is_normalized : bool True if all stamps are normalized
12071210 """
12081211 cdef:
1209- Py_ssize_t i, n = len (stamps)
1210- ndarray[int64_t] trans, deltas
1212+ Py_ssize_t pos, i, n = len (stamps)
1213+ ndarray[int64_t] trans
1214+ int64_t[:] deltas
12111215 npy_datetimestruct dts
12121216 int64_t local_val, delta
12131217
0 commit comments