Skip to content

Commit

Permalink
CLN/PERF: simplify tslib.get_time_micros (pandas-dev#18389)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel authored and jreback committed Nov 24, 2017
1 parent de5faf1 commit aec3347
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 24 deletions.
23 changes: 0 additions & 23 deletions pandas/_libs/tslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -730,29 +730,6 @@ cpdef array_to_datetime(ndarray[object] values, errors='raise',
return oresult


# ----------------------------------------------------------------------
# Accessors


def get_time_micros(ndarray[int64_t] dtindex):
"""
Datetime as int64 representation to a structured array of fields
"""
cdef:
Py_ssize_t i, n = len(dtindex)
pandas_datetimestruct dts
ndarray[int64_t] micros

micros = np.empty(n, dtype=np.int64)

for i in range(n):
dt64_to_dtstruct(dtindex[i], &dts)
micros[i] = 1000000LL * (dts.hour * 60 * 60 +
60 * dts.min + dts.sec) + dts.us

return micros


# ----------------------------------------------------------------------
# Some general helper functions

Expand Down
20 changes: 20 additions & 0 deletions pandas/_libs/tslibs/fields.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,26 @@ from np_datetime cimport (pandas_datetimestruct, pandas_timedeltastruct,
from nattype cimport NPY_NAT


def get_time_micros(ndarray[int64_t] dtindex):
"""
Return the number of microseconds in the time component of a
nanosecond timestamp.
Parameters
----------
dtindex : ndarray[int64_t]
Returns
-------
micros : ndarray[int64_t]
"""
cdef:
ndarray[int64_t] micros

micros = np.mod(dtindex, 86400000000000, dtype=np.int64) // 1000LL
return micros


def build_field_sarray(ndarray[int64_t] dtindex):
"""
Datetime as int64 representation to a structured array of fields
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ def _get_time_micros(self):
values = self.asi8
if self.tz is not None and self.tz is not utc:
values = self._local_timestamps()
return libts.get_time_micros(values)
return fields.get_time_micros(values)

def to_series(self, keep_tz=False):
"""
Expand Down

0 comments on commit aec3347

Please sign in to comment.