[Numpy-tickets] [NumPy] #348: Creating recarrays from numpy scalar voids fails

NumPy numpy-tickets at scipy.net
Mon Oct 16 10:14:43 CDT 2006


#348: Creating recarrays from numpy scalar voids fails
--------------------+-------------------------------------------------------
 Reporter:  faltet  |       Owner:  somebody
     Type:  defect  |      Status:  new     
 Priority:  normal  |   Milestone:          
Component:  Other   |     Version:  devel   
 Severity:  normal  |    Keywords:          
--------------------+-------------------------------------------------------
 Hi,

 Perhaps we've discussed this already, but I find the next a bit
 inconsistent. The next works consistently:

 {{{
 In [87]:numpy.rec.array((1, 2L), dtype=descr)
 Out[87]:
 recarray((1, 2L),
       dtype=[('x', '|u1'), ('y', '<u4')])
 In [88]:numpy.rec.array([(1, 2L)], dtype=descr)
 Out[88]:
 recarray([(1, 2L)],
       dtype=[('x', '|u1'), ('y', '<u4')])
 }}}

 i.e. a recarray with shape () or (1,) is returned depending on the shape
 of the input. However:

 {{{
 In [89]:numpy.rec.array(numpy.array((1, 2L), dtype=descr), dtype=descr)
 Out[89]:
 recarray((1, 2L),
       dtype=[('x', '|u1'), ('y', '<u4')])
 # Equals to 87, but...
 In [90]:numpy.rec.array([numpy.array((1, 2L), dtype=descr)], dtype=descr)
 ---------------------------------------------------------------------------
 exceptions.ValueError                                Traceback (most
 recent call last)

 /home/faltet/<ipython console>

 /usr/lib/python2.4/site-packages/numpy/core/records.py in array(obj,
 dtype, shape, offset, strides, formats, names, titles, aligned, byteorder,
 copy)
     512             return fromrecords(obj, dtype=dtype, shape=shape,
 **kwds)
     513         else:
 --> 514             return fromarrays(obj, dtype=dtype, shape=shape,
 **kwds)
     515
     516     elif isinstance(obj, recarray):

 /usr/lib/python2.4/site-packages/numpy/core/records.py in
 fromarrays(arrayList, dtype, shape, formats, names, titles, aligned,
 byteorder)
     296     # Determine shape from data-type.
     297     if len(descr) != len(arrayList):
 --> 298         raise ValueError, "mismatch between the number of fields
 "\
     299               "and the number of arrays"
     300

 ValueError: mismatch between the number of fields and the number of arrays

 }}}

 for me, the output for 90 should be similar to 88.

-- 
Ticket URL: <http://projects.scipy.org/scipy/numpy/ticket/348>
NumPy <http://projects.scipy.org/scipy/numpy>
The fundamental package needed for scientific computing with Python.


More information about the Numpy-tickets mailing list