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?
You can use issubdtype
:
np.issubdtype(comp.dtype, np.datetime64)
Currently I'm using:
assert 'datetime64' in str(comp.dtype)
It leaves a bad taste in my mouth (since it relies on other behavior), but its all I can some up with.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With