[pypy-issue] [issue1589] numpy: Structured arrays give odd behavior

Isaac Freeman tracker at bugs.pypy.org
Sat Aug 24 04:59:49 CEST 2013


New submission from Isaac Freeman <memotype at gmail.com>:

I'm running the latest nightly as of last night. Trying to construct structured
arrays from a list gives add characters and values in the resulting array:

numpypy:

In [76]: c = numpy.array([[(1,2,'a'),(3,4,'b')],[(5,6,'c'),(7,8,'d')]],
dtype=[('bg', 'i8'), ('fg', 'i8'), ('char', 'S1')] )

In [77]: c
Out[77]: 
'), (3, 4, '')],
       [(5, 6, ''), (7, 8, '')]], 
      dtype=void136)

(There are some non-printable characters in the output.)

Compared to numpy in cpython:

>>> c = numpy.array([[(1,2,'a'),(3,4,'b')],[(5,6,'c'),(7,8,'d')]], dtype=[('bg',
'i8'), ('fg', 'i8'), ('char', 'S1')])
>>> c
array([[(1, 2, 'a'), (3, 4, 'b')],
       [(5, 6, 'c'), (7, 8, 'd')]], 
      dtype=[('bg', '<i8'), ('fg', '<i8'), ('char', 'S1')])

This also affects array assignment. In numpypy:

In [83]: c = numpy.zeros((2,2,2), dtype=[('bg', 'i8'), ('fg', 'i8'), ('char', '\
S1')])

In [84]: c
Out[84]: 
array([[[(0, 0, ''), (0, 0, '')],
        [(0, 0, ''), (0, 0, '')]],

       [[(0, 0, ''), (0, 0, '')],
        [(0, 0, ''), (0, 0, '')]]], 
      dtype=void136)

In [85]: c[0,0] = (1, 2, 'a')
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-85-158a9c3d29f8> in <module>()
----> 1 c[0,0] = (1, 2, 'a')

ValueError: invalid literal for int() with base 10: 'a'

In [86]: 

And in numpy/cpython:

>>> c = numpy.zeros((2,2,2), dtype=[('bg', 'i8'), ('fg', 'i8'), ('char', '\
... S1')])
>>> c
array([[[(0, 0, ''), (0, 0, '')],
        [(0, 0, ''), (0, 0, '')]],

       [[(0, 0, ''), (0, 0, '')],
        [(0, 0, ''), (0, 0, '')]]], 
      dtype=[('bg', '<i8'), ('fg', '<i8'), ('char', 'S1')])
>>> c[0,0] = (1, 2, 'a')
>>> c[0,0]
array([(1, 2, 'a'), (1, 2, 'a')], 
      dtype=[('bg', '<i8'), ('fg', '<i8'), ('char', 'S1')])
>>>

----------
messages: 6091
nosy: memotype, pypy-issue
priority: bug
status: unread
title: numpy: Structured arrays give odd behavior

________________________________________
PyPy bug tracker <tracker at bugs.pypy.org>
<https://bugs.pypy.org/issue1589>
________________________________________


More information about the pypy-issue mailing list