numpy.isnat() method in python with examples
In this Python tutorial, we are going to learn about numpy.isnat() method. This method helps in figuring out whether the value returned by numpy.datetime64() and numpy.timedelta64() is a time or not. This function has a boolean return type and returns either True or False.
numpy.isnat() method takes one parameter and that should be the value returned by numpy.datetime64() or numpy.timedelta64() methods. Otherwise, it throws an error. The syntax for this function is given below:
The function returns True if the values returned by above mentioned time functions is not a time, else it returns False. Here are some example programs that will explain the working of numpy.isnat() method.
Have a look at the code given below.
import numpy as np ret = np.isnat(np.datetime64("1999-09-09")) ret
As you can see in the output, the np.isnat() returns False because ‘1999-09-09’ is a time. Now, look at the next example and its output.
import numpy as np ret = np.isnat(np.datetime64("Nat")) ret
This time the np.isnat() method returns True, as the datetime64() method returns a value which is not a time.
In this example, we are going to use deltatime64() to pass as argument in the np.isnat() method. See the code and the output.
ret = np.isnat(np.timedelta64(15, 'D')) ret
ret = np.isnat(np.timedelta64("Nat")) ret