[Numpy-discussion] Behavior of nan{max, min} and nanarg{max, min} for all-nan slices.

Daniele Nicolodi daniele at grinta.net
Thu Oct 3 15:44:34 EDT 2013

On 03/10/2013 20:59, Charles R Harris wrote:
> Here is what I have currently implemented. First, define an AllNanError
> class AllNanError(ValueError):
>     def __init__(self, msg, result):
>         ValueError.__init__(self, msg)
>         self.result = result
> For nanmax/nanmin/nanargmax/nanargmin this error is raised for all-nan axis
> and the result is attached. The exception can then be caught and the
> result examined. A ValueError is what amax, amin return for empty arrays.
> For nanmax/nanmin the result for an empty slice is nan. For
> argnanmax/argnanmin the result of an empty slice is -1, which is easier
> to read and remember than intp.min.

I think an error in this cases would be less confusing.

> A ValueError is what argmin, argmax
> currently return for empty arrays. Note that both of these functions can
> give wrong results if they contain some min/max values respectively.
> That is an old bug and I haven't fixed it.
> The nanmean/nanvar/nanstd functions currently raise a warning for
> all-nan slices and the result for such is nan. These could also be made
> to raise an error.

I think an error in that case would be more consistent.


More information about the NumPy-Discussion mailing list