@@ -16,6 +16,8 @@ from cpython.datetime cimport (datetime, tzinfo,
16
16
PyDateTime_CheckExact, PyDateTime_IMPORT)
17
17
PyDateTime_IMPORT
18
18
19
+ from ccalendar import DAY_SECONDS, HOUR_SECONDS
20
+
19
21
from np_datetime cimport (check_dts_bounds,
20
22
npy_datetimestruct,
21
23
pandas_datetime_to_datetimestruct, _string_to_dts,
@@ -41,8 +43,6 @@ from nattype cimport NPY_NAT, checknull_with_nat
41
43
# ----------------------------------------------------------------------
42
44
# Constants
43
45
44
- cdef int64_t DAY_NS = 86400000000000L L
45
- cdef int64_t HOURS_NS = 3600000000000
46
46
NS_DTYPE = np.dtype(' M8[ns]' )
47
47
TD_DTYPE = np.dtype(' m8[ns]' )
48
48
@@ -875,6 +875,7 @@ def tz_localize_to_utc(ndarray[int64_t] vals, object tz, object ambiguous=None,
875
875
Py_ssize_t delta_idx_offset, delta_idx, pos_left, pos_right
876
876
int64_t * tdata
877
877
int64_t v, left, right, val, v_left, v_right, new_local, remaining_mins
878
+ int64_t HOURS_NS = HOUR_SECONDS * 1000000000
878
879
ndarray[int64_t] result, result_a, result_b, dst_hours
879
880
npy_datetimestruct dts
880
881
bint infer_dst = False , is_dst = False , fill = False
@@ -931,10 +932,10 @@ def tz_localize_to_utc(ndarray[int64_t] vals, object tz, object ambiguous=None,
931
932
result_b[:] = NPY_NAT
932
933
933
934
idx_shifted_left = (np.maximum(0 , trans.searchsorted(
934
- vals - DAY_NS , side = ' right' ) - 1 )).astype(np.int64)
935
+ vals - DAY_SECONDS * 1000000000 , side = ' right' ) - 1 )).astype(np.int64)
935
936
936
937
idx_shifted_right = (np.maximum(0 , trans.searchsorted(
937
- vals + DAY_NS , side = ' right' ) - 1 )).astype(np.int64)
938
+ vals + DAY_SECONDS * 1000000000 , side = ' right' ) - 1 )).astype(np.int64)
938
939
939
940
for i in range (n):
940
941
val = vals[i]
@@ -1116,9 +1117,9 @@ def normalize_date(dt: object) -> datetime:
1116
1117
@ cython.boundscheck (False )
1117
1118
def normalize_i8_timestamps (int64_t[:] stamps , object tz = None ):
1118
1119
"""
1119
- Normalize each of the (nanosecond) timestamps in the given array by
1120
- rounding down to the beginning of the day (i.e. midnight). If `tz`
1121
- is not None, then this is midnight for this timezone.
1120
+ Normalize each of the (nanosecond) timezone aware timestamps in the given
1121
+ array by rounding down to the beginning of the day (i.e. midnight).
1122
+ This is midnight for timezone, `tz` .
1122
1123
1123
1124
Parameters
1124
1125
----------
@@ -1130,21 +1131,11 @@ def normalize_i8_timestamps(int64_t[:] stamps, object tz=None):
1130
1131
result : int64 ndarray of converted of normalized nanosecond timestamps
1131
1132
"""
1132
1133
cdef:
1133
- Py_ssize_t i, n = len (stamps)
1134
- npy_datetimestruct dts
1134
+ Py_ssize_t n = len (stamps)
1135
1135
int64_t[:] result = np.empty(n, dtype = np.int64)
1136
1136
1137
- if tz is not None :
1138
- tz = maybe_get_tz(tz)
1139
- result = _normalize_local(stamps, tz)
1140
- else :
1141
- with nogil:
1142
- for i in range (n):
1143
- if stamps[i] == NPY_NAT:
1144
- result[i] = NPY_NAT
1145
- continue
1146
- dt64_to_dtstruct(stamps[i], & dts)
1147
- result[i] = _normalized_stamp(& dts)
1137
+ tz = maybe_get_tz(tz)
1138
+ result = _normalize_local(stamps, tz)
1148
1139
1149
1140
return result.base # .base to access underlying np.ndarray
1150
1141
0 commit comments