Author: Matti Picus <matti.pi...@gmail.com> Branch: voidtype_strformat Changeset: r68221:889adc434d6e Date: 2013-11-18 22:03 +0200 http://bitbucket.org/pypy/pypy/changeset/889adc434d6e/
Log: add failing test, almost implement diff --git a/pypy/module/micronumpy/test/test_numarray.py b/pypy/module/micronumpy/test/test_numarray.py --- a/pypy/module/micronumpy/test/test_numarray.py +++ b/pypy/module/micronumpy/test/test_numarray.py @@ -3099,6 +3099,17 @@ 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')]], diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py --- a/pypy/module/micronumpy/types.py +++ b/pypy/module/micronumpy/types.py @@ -1789,6 +1789,25 @@ 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 @@ -1848,7 +1867,11 @@ 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) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit