How to fix NumPy timedelta64 TypeError: Invalid datetime unit "min" in metadata

Problem:

You want to construct a NumPy timedelta64 from a value in minutes using

example.py
np.timedelta64(1, 'min')

but you see an error message like

example.txt
Traceback (most recent call last):
  File "test.py", line 3, in <module>
    delta = np.timedelta64(1, 'min')
TypeError: Invalid datetime unit "min" in metadata

Solution

numpy uses m as specifier for minutes, not min! Change your code to

example.py
np.timedelta64(1, 'm')

 


Check out similar posts by category: Python