[Numpy-discussion] Proper NaN handling in max and co: a redux

Charles R Harris charlesr.harris at gmail.com
Fri Sep 26 08:29:02 EDT 2008


On Thu, Sep 25, 2008 at 10:56 PM, David Cournapeau <
david at ar.media.kyoto-u.ac.jp> wrote:

> Charles R Harris wrote:
> >
> > I'm also wondering about the sign ufunc. It should probably return nan
> > for nans, but -1,0,1 are the current values. We also need to decide
> > which end of the sorted values the nans should go to. I'm a bit
> > partial to the beginning but the end would be fine with me, it might
> > even be a bit more natural as searchsorted would find the beginning of
> > the nans by default.
>
> Note that in both suggest approaches, sort with NaN would raise an
> error. We could then provide a nansort, which ignore the NaN, and deal
> with your case; would it be hard to have an option for the beginning vs
> the end, or would that be difficult ?
>

It shouldn't be any more difficult to do either based on a keyword. Argsorts
shouldn't be a problem either. I'm thinking that the most flexible way to
handle the sorts is to make a preliminary pass through the data and collect
all the nans at one end or the other and sort the remainder. That would also
make it easy to raise an error if we wanted to and avoid an extra compare in
all the other sorting passes. That approach could probably be extended to
masked arrays also.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20080926/1e13f974/attachment.html>


More information about the NumPy-Discussion mailing list