Skip to content

Commit 2b9112a

Browse files
committed
edits per reviewer request
1 parent 12ccb9b commit 2b9112a

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
@@ -2312,13 +2312,6 @@ cdef inline _to_i8(object val):
23122312
return val
23132313

23142314

2315-
def i8_to_pydt(int64_t i8, object tzinfo=None):
2316-
"""
2317-
Inverse of pydt_to_i8
2318-
"""
2319-
return Timestamp(i8)
2320-
2321-
23222315
# ----------------------------------------------------------------------
23232316
# Accessors
23242317

pandas/_libs/tslibs/conversion.pxd

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

2828
cdef int64_t get_datetime64_nanos(object val) except? -1
2929

30-
cpdef pydt_to_i8(object pydt)
30+
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
@@ -1690,7 +1690,7 @@ def is_normalized(self):
16901690
"""
16911691
Returns True if all of the dates are at midnight ("no time")
16921692
"""
1693-
return conversion.are_dates_normalized(self.asi8, self.tz)
1693+
return conversion.is_date_array_normalized(self.asi8, self.tz)
16941694

16951695
@cache_readonly
16961696
def _resolution(self):

0 commit comments

Comments
 (0)