Numpy: Checking if a value is NaT

前端 未结 6 1655
余生分开走
余生分开走 2020-12-23 21:12
nat = np.datetime64(\'NaT\')
nat == nat
>> FutureWarning: In the future, \'NAT == x\' and \'x == NAT\' will always be False.

np.isnan(nat)
>> TypeError:         


        
6条回答
  •  Happy的楠姐
    2020-12-23 21:49

    This approach avoids the warnings while preserving the array-oriented evaluation.

    import numpy as np
    def isnat(x):
        """ 
        datetime64 analog to isnan.
        doesn't yet exist in numpy - other ways give warnings
        and are likely to change.  
        """
        return x.astype('i8') == np.datetime64('NaT').astype('i8')
    

提交回复
热议问题