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

前端 未结 2 1537
轮回少年
轮回少年 2021-01-02 09:04

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).

2条回答
  •  轮回少年
    2021-01-02 09:39

    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.

提交回复
热议问题