[Numpy-discussion] Mapping protocol to nested types in descriptor

Francesc Altet faltet at carabos.com
Mon Feb 6 10:53:14 CST 2006


Hi,

I've implemented a simple mapping protocol in the descriptor type so
that the user would be able to do:

In [138]:dtype = numpy.dtype([
   .....:    ('x', '<i4', (2,)),
   .....:    ('Info',[
   .....:        ('name', '<U120'),
   .....:        ('weight', '<f4')])])

In [139]:dtype['Info'].name
Out[139]:'void3872'

In [140]:dtype['Info']['name'].type
Out[140]:<type 'unicodescalar'>

instead of the current:

In [141]:dtype.fields['Info'][0].name
Out[141]:'void3872'

In [142]:dtype.fields['Info'][0].fields['name'][0].type
Out[142]:<type 'unicodescalar'>

which I find cumbersome to type. Find the patch for this in the
attachments.

OTOH, I've completed the tests for heterogeneous objects in
test_numerictypes.py. Now, there is a better check for both flat and
nested fields, as well as explicit checking of type descriptors
(including tests for the new mapping interface in descriptors). So far,
no more problems have been detected by the new tests :-). Please, note
that you will need the patch above applied in order to run the tests.
Travis, if you think that it would be better to do not apply the patch,
the tests can be easily adapted by changing lines like:

        self.assert_(h.dtype['x'][0].name[:4] == 'void') 

by

        self.assert_(h.dtype.fields['x'][0].name[:4] == 'void') 

Cheers,

-- 
>0,0<   Francesc Altet     http://www.carabos.com/
V   V   Cárabos Coop. V.   Enjoy Data
 "-"

-------------- next part --------------
A non-text attachment was scrubbed...
Name: arrayobject.c.patch
Type: text/x-patch
Size: 2654 bytes
Desc: not available
Url : http://projects.scipy.org/pipermail/numpy-discussion/attachments/20060206/52093d2b/attachment-0001.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_numerictypes.py
Type: text/x-python
Size: 12824 bytes
Desc: not available
Url : http://projects.scipy.org/pipermail/numpy-discussion/attachments/20060206/52093d2b/attachment-0001.py 


More information about the Numpy-discussion mailing list