obsplus.utils.time.to_datetime64¶
- obsplus.utils.time.to_datetime64(value, default=NaT)[source]¶
Convert time value to a numpy datetime64, or array of such.
This function essentially uses the same logic as ~:class:obspy.UTCDateTime but also accounts for native numpy types.
- Parameters:
value (
Union
[str
,UTCDateTime
,float
,datetime64
,Timestamp
,Sequence
[Union
[str
,UTCDateTime
,float
,datetime64
,Timestamp
]],None
]) – Any value that can be interpreted as a time. If a sequence is passed an ndarray of type “datetime64[ns]” is returned.default – A value for missing data. pandas.NaT is used by default.
- Return type:
Union
[datetime64
,ndarray
,Series
]
Examples
>>> import obspy >>> import pandas as pd >>> timestr = '2020-01-03T11:00:00' >>> inputs = [obspy.UTCDateTime(timestr), None, 2525, np.datetime64(timestr)] >>> out = to_datetime64(inputs) >>> for t in out: ... assert isinstance(t, np.datetime64) or pd.isnull(t) >>> assert pd.isnull(out[1])