[Numpy-discussion] A couple of errors in numpy/records.py

Francesc Altet faltet at carabos.com
Tue Jan 31 09:17:07 CST 2006


Hi,

I've detected a couple of issues in records.py. For the first one, the
next should fix it:

Index: numpy/core/records.py
===================================================================
--- numpy/core/records.py       (revision 2033)
+++ numpy/core/records.py       (working copy)
@@ -410,7 +410,8 @@
                         offset=offset)
     elif isinstance(obj, sb.ndarray):
         res = obj.view(recarray)
-        if issubclass(res.dtype, nt.void):
+        if issubclass(res.dtype.type, nt.void):
             res.dtype = sb.dtype((record, res.dtype))
+       return res
     else:
         raise ValueError("Unknown input type")

Now, another curious thing (sorry, no patch this time):

In [6]: for i in numpy.rec.array([(1,2)], formats='u4,u4'): print i
   ...:
(1L, 2L)

[No problem with this]

In [7]: for i in numpy.rec.array([(1,2)], formats='u4,u4')[0]: print i
   ...:
---------------------------------------------------------------------------
exceptions.KeyError                                  Traceback (most recent 
call last)

/home/faltet/computacio.nobackup/hdf5-1.7.51/test/<console>

/usr/lib/python2.3/site-packages/numpy/core/records.py in __getitem__(self, 
obj)
    126
    127     def __getitem__(self, obj):
--> 128         return self.getfield(*(self.dtype.fields[obj][:2]))
    129
    130     def __setitem__(self, obj, val):

KeyError: 0

I'd expect something like

1L
2L

Cheers,

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





More information about the Numpy-discussion mailing list