@@ -16,6 +16,8 @@ from cpython.datetime cimport (datetime, tzinfo,
1616 PyDateTime_CheckExact, PyDateTime_IMPORT)
1717PyDateTime_IMPORT
1818
19+ from ccalendar import DAY_SECONDS, HOUR_SECONDS
20+
1921from np_datetime cimport (check_dts_bounds,
2022 npy_datetimestruct,
2123 pandas_datetime_to_datetimestruct, _string_to_dts,
@@ -41,8 +43,6 @@ from nattype cimport NPY_NAT, checknull_with_nat
4143# ----------------------------------------------------------------------
4244# Constants
4345
44- cdef int64_t DAY_NS = 86400000000000L L
45- cdef int64_t HOURS_NS = 3600000000000
4646NS_DTYPE = np.dtype(' M8[ns]' )
4747TD_DTYPE = np.dtype(' m8[ns]' )
4848
@@ -875,6 +875,7 @@ def tz_localize_to_utc(ndarray[int64_t] vals, object tz, object ambiguous=None,
875875 Py_ssize_t delta_idx_offset, delta_idx, pos_left, pos_right
876876 int64_t * tdata
877877 int64_t v, left, right, val, v_left, v_right, new_local, remaining_mins
878+ int64_t HOURS_NS = HOUR_SECONDS * 1000000000
878879 ndarray[int64_t] result, result_a, result_b, dst_hours
879880 npy_datetimestruct dts
880881 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,
931932 result_b[:] = NPY_NAT
932933
933934 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)
935936
936937 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)
938939
939940 for i in range (n):
940941 val = vals[i]
@@ -1116,9 +1117,9 @@ def normalize_date(dt: object) -> datetime:
11161117@ cython.boundscheck (False )
11171118def normalize_i8_timestamps (int64_t[:] stamps , object tz = None ):
11181119 """
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` .
11221123
11231124 Parameters
11241125 ----------
@@ -1130,21 +1131,11 @@ def normalize_i8_timestamps(int64_t[:] stamps, object tz=None):
11301131 result : int64 ndarray of converted of normalized nanosecond timestamps
11311132 """
11321133 cdef:
1133- Py_ssize_t i, n = len (stamps)
1134- npy_datetimestruct dts
1134+ Py_ssize_t n = len (stamps)
11351135 int64_t[:] result = np.empty(n, dtype = np.int64)
11361136
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)
11481139
11491140 return result.base # .base to access underlying np.ndarray
11501141
0 commit comments