Skip to content
21 changes: 11 additions & 10 deletions pandas/_libs/tslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1701,20 +1701,21 @@ cpdef array_to_datetime(ndarray[object] values, errors='raise',

def get_time_micros(ndarray[int64_t] dtindex):
"""
Datetime as int64 representation to a structured array of fields
Return the number of microseconds in the time component of a
nanosecond timestamp.

Parameters
----------
dtindex : ndarray[int64_t]

Returns
-------
micros : ndarray[int64_t]
"""
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

micros = np.mod(dtindex, 86400000000000, dtype=np.int64) // 1000LL
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pretty sure we have a constant somewhere rather than hard-coding 86400.....

also shouldn't this routine be in conversion?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

conversion would be reasonable. fields might be a better fit. I'm actually leaning towards "this doesn't need to be a function" since its a one-linear and only used once.

The constant you're thinking of is defined in conversion.

return micros


Expand Down