Commits

Brian Kearns committed eb44db8

provide RecordType.to_builtin_type

Comments (0)

Files changed (2)

pypy/module/micronumpy/test/test_numarray.py

         assert array([1]).item() == 1
         a = array('x')
         assert a.item() == 'x'
+        a = array([(1, 'abc')], dtype=[('a', int), ('b', 'S2')])
+        b = a.item(0)
+        assert type(b) is tuple
+        assert type(b[0]) is int
+        assert type(b[1]) is str
+        assert b[0] == 1
+        assert b[1] == 'ab'
 
     def test_int_array_index(self):
         from numpypy import array

pypy/module/micronumpy/types.py

 
     def store(self, arr, i, offset, box):
         assert isinstance(box, interp_boxes.W_StringBox)
-        size = min(arr.dtype.size, box.arr.size - box.ofs)
+        size = min(arr.dtype.size - offset, box.arr.size - box.ofs)
         return self._store(arr.storage, i, offset, box, size)
 
     @jit.unroll_safe
         for k in range(box.arr.dtype.get_size()):
             arr.storage[k + i] = box.arr.storage[k + box.ofs]
 
+    def to_builtin_type(self, space, box):
+        assert isinstance(box, interp_boxes.W_VoidBox)
+        items = []
+        dtype = box.dtype
+        for name in dtype.fieldnames:
+            ofs, subdtype = dtype.fields[name]
+            itemtype = subdtype.itemtype
+            subbox = itemtype.read(box.arr, box.ofs, ofs, subdtype)
+            items.append(itemtype.to_builtin_type(space, subbox))
+        return space.newtuple(items)
+
     @jit.unroll_safe
     def str_format(self, box):
         assert isinstance(box, interp_boxes.W_VoidBox)