function of dascore.utils.time source

    obj: float | numpy.ndarray | str | datetime.timedelta[float, ndarray, str, timedelta] ,

Convert an object to timedelta64.

This function accepts a wide range of inputs and returns something of the same shape, but converted to numpy’s timedelta64 representation.


Parameter Description
obj An object to convert to timedelta64. Can be a float, str or arary of
such. Floats are interpreted as seconds and strings must conform to
the output style of timedeltas (e.g. str(time_delta)).


import dascore as dc

# Convert a float to timedelta64 representing seconds.
td_1 = dc.to_timedelta64(10.1232)

# This also works on negative numbers.
td_2 = dc.to_datetime64(-10.5)

# Convert a string to timedelta64
td_str = "1000000000 nanoseconds"
td_3 = dc.to_timedelta64(td_str)