Commits

mattip committed 889adc4

add failing test, almost implement

  • Participants
  • Parent commits b6c763c
  • Branches voidtype_strformat

Comments (0)

Files changed (2)

File pypy/module/micronumpy/test/test_numarray.py

 
         assert len(list(a[0])) == 2
 
+    def test_3d_record(self):
+        from numpypy import dtype, array
+        dt = dtype([('name', 'S4'), ('x', float), ('y', float),
+                    ('block', int, (2, 2, 3))])
+        a = array([('aaaa', 1.0, 8.0, [[[1, 2, 3], [4, 5, 6]],
+                                       [[7, 8, 9], [10, 11, 12]]])],
+                  dtype=dt)
+        s = str(a)
+        assert s.endswith("[('aaaa', 1.0, 8.0, [[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]])]")
+
+
     def test_issue_1589(self):
         import numpypy as numpy
         c = numpy.array([[(1, 2, 'a'), (3, 4, 'b')], [(5, 6, 'c'), (7, 8, 'd')]],

File pypy/module/micronumpy/types.py

                                     dtype.subdtype)
         return W_NDimArray(implementation)
 
+    def str_format(self, val):
+        # only called with the results of readarray()
+        from pypy.module.micronumpy.base import W_NDimArray
+        assert isinstance(val, W_NDimArray)
+        i = val.create_iter()
+        first = True
+        dtype = val.get_dtype()
+        s = StringBuilder()
+        s.append('[')
+        while not i.done():
+            if first:
+                first = False
+            else:
+                s.append(', ')
+            s.append(dtype.itemtype.str_format(i.getitem()))
+            i.next()
+        s.append(']')
+        return s.build()
+
 class RecordType(FlexibleType):
     T = lltype.Char
 
                 first = False
             else:
                 pieces.append(", ")
-            pieces.append(tp.str_format(tp.read(box.arr, box.ofs, ofs)))
+            if isinstance(tp, VoidType):
+                val = tp.readarray(box.arr, box.ofs, ofs, subdtype)
+            else:
+                val = tp.read(box.arr, box.ofs, ofs, subdtype)
+            pieces.append(tp.str_format(val))
         pieces.append(")")
         return "".join(pieces)