【发布时间】:2016-11-25 08:37:32
【问题描述】:
nat = np.datetime64('NaT')
nat == nat
>> FutureWarning: In the future, 'NAT == x' and 'x == NAT' will always be False.
np.isnan(nat)
>> TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
如何检查 datetime64 是否为 NaT?我似乎无法从文档中挖掘出任何东西。我知道 Pandas 可以做到,但我不想为这么基本的东西添加依赖项。
【问题讨论】:
-
你可以和
np.datetime64('NaT')比较其实:nat == np.datetime64('NaT')输出:True。 -
您使用的是 1.11.1 吗?无法再比较 NaT:github.com/numpy/numpy/blob/master/doc/release/1.11.0-notes.rst
-
我很抱歉,这是我的疏忽。 1. 现在你可以比较
nat == nat,它会返回True。 2. 正如github中所说,在numpy 1.12.0中你仍然可以比较NaT:nat != np.datetime64('NaT')将返回True,否则所有涉及NaT的比较都将返回False。所以,最后的结论:首先你需要检查numpy的版本,然后选择如何比较NaT的。 -
您能否提供一个如何检查值是否为 NaT 的示例?无论使用什么运算符,我仍然会收到警告。
-
你能不接受瓦迪姆的回答吗? FutureWarning 表示 NumPy 开发人员计划进行更改,以便答案不再有效。