@@ -91,7 +91,7 @@ def ensure_datetime64ns(ndarray arr, copy=True):
91
91
"""
92
92
cdef:
93
93
Py_ssize_t i, n = arr.size
94
- ndarray[ int64_t] ivalues, iresult
94
+ int64_t[: ] ivalues, iresult
95
95
NPY_DATETIMEUNIT unit
96
96
npy_datetimestruct dts
97
97
@@ -139,7 +139,7 @@ def ensure_timedelta64ns(ndarray arr, copy=True):
139
139
return arr.astype(TD_DTYPE, copy = copy)
140
140
141
141
142
- def datetime_to_datetime64 (ndarray[ object] values ):
142
+ def datetime_to_datetime64 (object[: ] values ):
143
143
"""
144
144
Convert ndarray of datetime-like objects to int64 array representing
145
145
nanosecond timestamps.
@@ -156,7 +156,7 @@ def datetime_to_datetime64(ndarray[object] values):
156
156
cdef:
157
157
Py_ssize_t i, n = len (values)
158
158
object val, inferred_tz = None
159
- ndarray[ int64_t] iresult
159
+ int64_t[: ] iresult
160
160
npy_datetimestruct dts
161
161
_TSObject _ts
162
162
@@ -525,7 +525,8 @@ cdef inline void localize_tso(_TSObject obj, tzinfo tz):
525
525
Sets obj.tzinfo inplace, alters obj.dts inplace.
526
526
"""
527
527
cdef:
528
- ndarray[int64_t] trans, deltas
528
+ ndarray[int64_t] trans
529
+ int64_t[:] deltas
529
530
int64_t local_val
530
531
Py_ssize_t pos
531
532
@@ -631,15 +632,16 @@ cdef inline int64_t[:] _tz_convert_dst(ndarray[int64_t] values, tzinfo tz,
631
632
cdef:
632
633
Py_ssize_t n = len (values)
633
634
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
637
639
int64_t v
638
640
639
641
trans, deltas, typ = get_dst_info(tz)
640
642
if not to_utc:
641
643
# We add `offset` below instead of subtracting it
642
- deltas = - 1 * deltas
644
+ deltas = - 1 * np.array( deltas, dtype = ' i8 ' )
643
645
644
646
tt = values[values != NPY_NAT]
645
647
if not len (tt):
@@ -728,7 +730,7 @@ cpdef int64_t tz_convert_single(int64_t val, object tz1, object tz2):
728
730
converted: int64
729
731
"""
730
732
cdef:
731
- ndarray[ int64_t] trans, deltas
733
+ int64_t[:] deltas
732
734
Py_ssize_t pos
733
735
int64_t v, offset, utc_date
734
736
npy_datetimestruct dts
@@ -756,7 +758,7 @@ cpdef int64_t tz_convert_single(int64_t val, object tz1, object tz2):
756
758
else :
757
759
# Convert UTC to other timezone
758
760
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
760
762
# line is sensitive to the declared return type of _tz_convert_dst;
761
763
# if it is declared as returning ndarray[int64_t], a compile-time error
762
764
# is raised.
@@ -781,10 +783,9 @@ def tz_convert(ndarray[int64_t] vals, object tz1, object tz2):
781
783
"""
782
784
783
785
cdef:
784
- ndarray[int64_t] utc_dates, tt, result, trans, deltas
786
+ ndarray[int64_t] utc_dates, result
785
787
Py_ssize_t i, j, pos, n = len (vals)
786
- int64_t v, offset, delta
787
- npy_datetimestruct dts
788
+ int64_t v
788
789
789
790
if len (vals) == 0 :
790
791
return np.array([], dtype = np.int64)
@@ -843,7 +844,8 @@ def tz_localize_to_utc(ndarray[int64_t] vals, object tz, object ambiguous=None,
843
844
localized : ndarray[int64_t]
844
845
"""
845
846
cdef:
846
- ndarray[int64_t] trans, deltas, idx_shifted
847
+ ndarray[int64_t] trans
848
+ int64_t[:] deltas, idx_shifted
847
849
ndarray ambiguous_array
848
850
Py_ssize_t i, idx, pos, ntrans, n = len (vals)
849
851
int64_t * tdata
@@ -1069,7 +1071,7 @@ def normalize_date(object dt):
1069
1071
1070
1072
@ cython.wraparound (False )
1071
1073
@ cython.boundscheck (False )
1072
- def normalize_i8_timestamps (ndarray[ int64_t] stamps , tz = None ):
1074
+ def normalize_i8_timestamps (int64_t[: ] stamps , tz = None ):
1073
1075
"""
1074
1076
Normalize each of the (nanosecond) timestamps in the given array by
1075
1077
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):
1087
1089
cdef:
1088
1090
Py_ssize_t i, n = len (stamps)
1089
1091
npy_datetimestruct dts
1090
- ndarray[ int64_t] result = np.empty(n, dtype = np.int64)
1092
+ int64_t[: ] result = np.empty(n, dtype = np.int64)
1091
1093
1092
1094
if tz is not None :
1093
1095
tz = maybe_get_tz(tz)
@@ -1101,12 +1103,12 @@ def normalize_i8_timestamps(ndarray[int64_t] stamps, tz=None):
1101
1103
dt64_to_dtstruct(stamps[i], & dts)
1102
1104
result[i] = _normalized_stamp(& dts)
1103
1105
1104
- return result
1106
+ return result.base # .base to access underlying np.ndarray
1105
1107
1106
1108
1107
1109
@ cython.wraparound (False )
1108
1110
@ 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):
1110
1112
"""
1111
1113
Normalize each of the (nanosecond) timestamps in the given array by
1112
1114
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):
1123
1125
"""
1124
1126
cdef:
1125
1127
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
1128
1131
Py_ssize_t[:] pos
1129
1132
npy_datetimestruct dts
1130
1133
int64_t delta
@@ -1190,7 +1193,7 @@ cdef inline int64_t _normalized_stamp(npy_datetimestruct *dts) nogil:
1190
1193
return dtstruct_to_dt64(dts)
1191
1194
1192
1195
1193
- def is_date_array_normalized (ndarray[ int64_t] stamps , tz = None ):
1196
+ def is_date_array_normalized (int64_t[: ] stamps , tz = None ):
1194
1197
"""
1195
1198
Check if all of the given (nanosecond) timestamps are normalized to
1196
1199
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):
1206
1209
is_normalized : bool True if all stamps are normalized
1207
1210
"""
1208
1211
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
1211
1215
npy_datetimestruct dts
1212
1216
int64_t local_val, delta
1213
1217
0 commit comments