[Numpy-discussion] np.sign and object comparisons

Nathaniel Smith njs at pobox.com
Tue Sep 1 02:49:50 EDT 2015


On Sun, Aug 30, 2015 at 9:09 PM, Jaime Fernández del Río <
jaime.frio at gmail.com> wrote:

>
> There are three ways of fixing this that I see:
>
>    1. Arbitrarily choose a value to set the return to. This is equivalent
>    to choosing a default return for `cmp` for comparisons. This preserves
>    behavior, but feels wrong.
>    2. Similarly to how np.sign of a floating point array with nans
>    returns nan for those values, return e,g, None for these cases. This
>    is my preferred option.
>    3. Raise an error, along the lines of the TypeError: unorderable types
>    that 3.x produces for some comparisons.
>
> Having read the other replies so far -- given that no-one seems to have
any clear intuition or use cases, I guess I find option 3 somewhat
tempting... it keeps our options open until someone who actually cares
comes along with a use case to hone our intuition on, and is very safe in
the mean time.

(This was noticed in the course of routine code cleanups, right, not an
external bug report? For all we know right now, no actual user has ever
even tried to apply np.sign to an object array?)

-n

-- 
Nathaniel J. Smith -- http://vorpus.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20150831/4738a5cd/attachment.html>


More information about the NumPy-Discussion mailing list