Discussion:
[Numpy-discussion] isnan() equivalent for np.NaT?
Scott Sanderson
2016-07-18 21:20:33 UTC
Permalink
Hi All,

I'm working on upgrading Zipline (github.com/quantopian/zipline) to the
latest numpy, and I'm getting a FutureWarnings about the upcoming change in
the behavior of comparisons on np.NaT. I'd like to be able to do checks
for NaT in a way that's forwards-compatible, but I couldn't find a function
analogous to `np.isnan` for NaT. Am I missing something that already
exists? If not, is there interest in such a function? I'd like to be able
to pre-emptively fix the warnings in Zipline so that we're ready when the
change actually happens, but it doesn't seem like the necessary tools are
available right now.

-Scott
Gerrit Holl
2016-07-18 22:39:15 UTC
Permalink
Post by Scott Sanderson
I'm working on upgrading Zipline (github.com/quantopian/zipline) to the
latest numpy, and I'm getting a FutureWarnings about the upcoming change in
the behavior of comparisons on np.NaT. I'd like to be able to do checks for
NaT in a way that's forwards-compatible, but I couldn't find a function
analogous to `np.isnan` for NaT. Am I missing something that already
exists? If not, is there interest in such a function? I'd like to be able
to pre-emptively fix the warnings in Zipline so that we're ready when the
change actually happens, but it doesn't seem like the necessary tools are
available right now.
Hi Scott,

see https://github.com/numpy/numpy/issues/5610

Gerrit.
Stephan Hoyer
2016-07-18 23:35:59 UTC
Permalink
Agreed -- this would be really nice to have. For now, the best you can do
is something like the following:


def is_na(x):
x = np.asarray(x)
if np.issubdtype(x.dtype, (np.datetime64, np.timedelta64)): # ugh
int_min = np.iinfo(np.int64).min
return x.view('int64') == int_min
else:
return np.isnan(x)
Post by Gerrit Holl
Post by Scott Sanderson
I'm working on upgrading Zipline (github.com/quantopian/zipline) to the
latest numpy, and I'm getting a FutureWarnings about the upcoming change
in
Post by Scott Sanderson
the behavior of comparisons on np.NaT. I'd like to be able to do checks
for
Post by Scott Sanderson
NaT in a way that's forwards-compatible, but I couldn't find a function
analogous to `np.isnan` for NaT. Am I missing something that already
exists? If not, is there interest in such a function? I'd like to be
able
Post by Scott Sanderson
to pre-emptively fix the warnings in Zipline so that we're ready when the
change actually happens, but it doesn't seem like the necessary tools are
available right now.
Hi Scott,
see https://github.com/numpy/numpy/issues/5610
Gerrit.
_______________________________________________
NumPy-Discussion mailing list
https://mail.scipy.org/mailman/listinfo/numpy-discussion
Loading...