[Numpy-discussion] possible bug in dtype for records

Travis Oliphant oliphant at ee.byu.edu
Wed Feb 15 11:27:14 CST 2006


Stefan van der Walt wrote:

>Using
>
>In [3]: numpy.__version__
>Out[3]: '0.9.5.2024'
>
>I see the following:
>
>In [4]: import numpy as N
>
>In [5]: ctype = N.dtype({'names': ('x', 'y', 'z'), 'formats' : [N.float32, N.float32, N.float32]})
>
>In [6]: ctype
>Out[6]: dtype([('x', '<f4'), ('y', '<f4'), ('z', '<f4')])
>
>In [7]: N.array([(1,2,3), (4,5,6)], dtype=ctype)
>Segmentation fault
>
>However, when I use a mutable list for defining dtype, i.e.
>
>'names': ['x', 'y', 'z'] instead of
>'names': ('x', 'y', 'z')
>
>it works fine.
>
>Is this expected behaviour?
>  
>

Got it.  Basically, the VOID_setitem code expected the special -1 entry 
in the fields dictionary to be a list, but it was never enforced.  So, 
when you entered a tuple like this problems arose.

I changed it in SVN so that the -1 entry is always a tuple (you can't 
change the fields names anyway unless you define a new data-type) so its 
more aptly described as a tuple.

Thanks again for finding this...

-Travis





More information about the Numpy-discussion mailing list