Consistent way to check if an np.array is datetime-like

datetime, numpy

Solution

You can use `issubdtype`:

np.issubdtype(comp.dtype, np.datetime64)

Problem

I'm dong some unit testing and I need to make sure a function always returns a np.datetime64-like object. However, they can be of any unit (year, day, nanosecond, etc). I've tried: ``` comp = function_returns_datetime_array(inp) assert isinstance(comp.dtype, np.datetime64) assert issubclass(comp.dtype, np.datetime64) assert issubclass(type(comp.dtype), np.datetime64) ``` Any suggestions?

Original source