@@ -89,7 +89,7 @@ cdef class _TSObject:
8989 return self .value
9090
9191
92- cpdef pydt_to_i8(object pydt):
92+ cpdef int64_t pydt_to_i8(object pydt) except ? - 1 :
9393 """
9494 Convert to int64 representation compatible with numpy datetime64; converts
9595 to UTC
@@ -102,6 +102,14 @@ cpdef pydt_to_i8(object pydt):
102102 return ts.value
103103
104104
105+ def i8_to_pydt (int64_t i8 , object tzinfo = None ):
106+ """
107+ Inverse of pydt_to_i8
108+ """
109+ from pandas import Timestamp
110+ return Timestamp(i8)
111+
112+
105113cdef convert_to_tsobject(object ts, object tz, object unit,
106114 bint dayfirst, bint yearfirst):
107115 """
@@ -793,6 +801,15 @@ cdef inline str _render_tstamp(int64_t val):
793801@ cython.wraparound (False )
794802@ cython.boundscheck (False )
795803def date_normalize (ndarray[int64_t] stamps , tz = None ):
804+ """
805+ Normalize each of the (nanosecond) timestamps in the given array by
806+ rounding down to the beginning of the day (i.e. midnight). If `tz`
807+ is not None, then this is midnight for this timezone.
808+
809+ Returns
810+ -------
811+ result : int64 ndarray of converted of normalized nanosecond timestamps
812+ """
796813 cdef:
797814 Py_ssize_t i, n = len (stamps)
798815 pandas_datetimestruct dts
@@ -815,7 +832,16 @@ def date_normalize(ndarray[int64_t] stamps, tz=None):
815832
816833@ cython.wraparound (False )
817834@ cython.boundscheck (False )
818- cdef _normalize_local(ndarray[int64_t] stamps, object tz):
835+ cdef ndarray[int64_t] _normalize_local(ndarray[int64_t] stamps, object tz):
836+ """
837+ Normalize each of the (nanosecond) timestamps in the given array by
838+ rounding down to the beginning of the day (i.e. midnight) for the
839+ given timezone `tz`.
840+
841+ Returns
842+ -------
843+ result : int64 ndarray of converted of normalized nanosecond timestamps
844+ """
819845 cdef:
820846 Py_ssize_t n = len (stamps)
821847 ndarray[int64_t] result = np.empty(n, dtype = np.int64)
@@ -879,7 +905,16 @@ cdef inline int64_t _normalized_stamp(pandas_datetimestruct *dts) nogil:
879905 return dtstruct_to_dt64(dts)
880906
881907
882- def are_dates_normalized (ndarray[int64_t] stamps , tz = None ):
908+ def bint is_date_array_normalized (ndarray[int64_t] stamps, tz= None ):
909+ """
910+ Check if all of the given (nanosecond) timestamps are normalized to
911+ midnight, i.e. hour == minute == second == 0. If the optional timezone
912+ `tz` is not None, then this is midnight for this timezone.
913+
914+ Returns
915+ -------
916+ is_normalizaed : bool True if all stamps are normalized
917+ """
883918 cdef:
884919 Py_ssize_t i, n = len (stamps)
885920 ndarray[int64_t] trans, deltas
0 commit comments