@@ -89,7 +89,7 @@ cdef class _TSObject:
89
89
return self .value
90
90
91
91
92
- cpdef pydt_to_i8(object pydt):
92
+ cpdef int64_t pydt_to_i8(object pydt) except ? - 1 :
93
93
"""
94
94
Convert to int64 representation compatible with numpy datetime64; converts
95
95
to UTC
@@ -102,6 +102,14 @@ cpdef pydt_to_i8(object pydt):
102
102
return ts.value
103
103
104
104
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
+
105
113
cdef convert_to_tsobject(object ts, object tz, object unit,
106
114
bint dayfirst, bint yearfirst):
107
115
"""
@@ -793,6 +801,15 @@ cdef inline str _render_tstamp(int64_t val):
793
801
@ cython.wraparound (False )
794
802
@ cython.boundscheck (False )
795
803
def 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
+ """
796
813
cdef:
797
814
Py_ssize_t i, n = len (stamps)
798
815
pandas_datetimestruct dts
@@ -815,7 +832,16 @@ def date_normalize(ndarray[int64_t] stamps, tz=None):
815
832
816
833
@ cython.wraparound (False )
817
834
@ 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
+ """
819
845
cdef:
820
846
Py_ssize_t n = len (stamps)
821
847
ndarray[int64_t] result = np.empty(n, dtype = np.int64)
@@ -879,7 +905,16 @@ cdef inline int64_t _normalized_stamp(pandas_datetimestruct *dts) nogil:
879
905
return dtstruct_to_dt64(dts)
880
906
881
907
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
+ """
883
918
cdef:
884
919
Py_ssize_t i, n = len (stamps)
885
920
ndarray[int64_t] trans, deltas
0 commit comments