On Thu, Jan 23, 2014 at 1:49 PM, Chris Barker <chris.bar...@noaa.gov> wrote:

>
> s = 'a string'
> np.array((s,), dtype='S')[0] == s
>
> Gives you False, rather than True on py2. This is because a py3 string is
> translated to the 'S' type (presumable with the default encoding, another
> maybe not a good idea, but returns a bytes object, which does not compare
> true to a py3 string. YOu can work aroudn this with varios calls to encode()
> and decode, and/or using b'a string', but that is ugly, kludgy, and doesn't
> work well with the py3 text model.

I think this is just inconsistent casting rules in numpy,

numpy should either refuse to assign the wrong type, instead of using
the repr as in some of the earlier examples of Oscar

>>> s = np.inf
>>> np.array((s,), dtype=int)[0] == s
Traceback (most recent call last):
  File "<pyshell#126>", line 1, in <module>
    np.array((s,), dtype=int)[0] == s
OverflowError: cannot convert float infinity to integer

or use the **same** conversion/casting rules also during the
interaction with python as are used in assignments and array creation.

Josef
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to