[Numpy-discussion] NumPy should not silently promote numbers to strings

Thomas Caswell tcaswell at gmail.com
Wed Feb 14 15:47:58 EST 2018


This has recently been a major point point for Matplotlib for the
implementation of string-categoricals as well.

Having numpy go to object or fail on `np.asarray([1, 2, 'foo'])` would make
things much easier for us.

Tom

On Fri, Feb 9, 2018 at 2:22 AM Stephan Hoyer <shoyer at gmail.com> wrote:

> On Thu, Feb 8, 2018 at 11:00 PM Eric Wieser <wieser.eric+numpy at gmail.com>
> wrote:
>
>> Presumably you would extend that to all (str, np.number), or even (str,
>> np.generic_)?
>>
> Yes, I'm currently doing (np.character, np.number) and (np.character,
> np.bool_). But only in direct consultation with the diagram of NumPy's
> type hierarchy :).
>
>> I suppose there’s the argument that with python-3-only support around the
>> corner, even (str, bytes) should go to object.
>>
> Yes, that's also pretty bad.
>
> The current behavior (str, bytes) -> str relies on bytes being valid ASCII:
> >>> np.array([b'\xFF', u'cd'])
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0:
> ordinal not in range(128)
>
> It exactly matches Python 2's str/unicode behavior, but doesn't make sense
> at all in a Python 3 world.
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at python.org
> https://mail.python.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20180214/e71e213d/attachment.html>


More information about the NumPy-Discussion mailing list