Skip to content

Commit ec6757f

Browse files
committed
edits per reviewer request
1 parent 3c7e5aa commit ec6757f

File tree

4 files changed

+40
-12
lines changed

4 files changed

+40
-12
lines changed

pandas/_libs/tslib.pyx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,13 +1848,6 @@ cdef inline _to_i8(object val):
18481848
return val
18491849

18501850

1851-
def i8_to_pydt(int64_t i8, object tzinfo=None):
1852-
"""
1853-
Inverse of pydt_to_i8
1854-
"""
1855-
return Timestamp(i8)
1856-
1857-
18581851
# ----------------------------------------------------------------------
18591852
# Accessors
18601853

pandas/_libs/tslibs/conversion.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ cpdef int64_t tz_convert_single(int64_t val, object tz1, object tz2)
2929

3030
cdef int64_t get_datetime64_nanos(object val) except? -1
3131

32-
cpdef pydt_to_i8(object pydt)
32+
cpdef int64_t pydt_to_i8(object pydt) except? -1

pandas/_libs/tslibs/conversion.pyx

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
105113
cdef 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)
795803
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+
"""
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

pandas/core/indexes/datetimes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1682,7 +1682,7 @@ def is_normalized(self):
16821682
"""
16831683
Returns True if all of the dates are at midnight ("no time")
16841684
"""
1685-
return conversion.are_dates_normalized(self.asi8, self.tz)
1685+
return conversion.is_date_array_normalized(self.asi8, self.tz)
16861686

16871687
@cache_readonly
16881688
def _resolution(self):

0 commit comments

Comments
 (0)