[pypy-commit] pypy default: fix more dtype str/repr cases

bdkearns noreply at buildbot.pypy.org
Mon Feb 24 09:09:36 CET 2014


Author: Brian Kearns <bdkearns at gmail.com>
Branch: 
Changeset: r69342:cb3ee4379850
Date: 2014-02-23 21:23 -0500
http://bitbucket.org/pypy/pypy/changeset/cb3ee4379850/

Log:	fix more dtype str/repr cases

diff --git a/pypy/module/micronumpy/interp_dtype.py b/pypy/module/micronumpy/interp_dtype.py
--- a/pypy/module/micronumpy/interp_dtype.py
+++ b/pypy/module/micronumpy/interp_dtype.py
@@ -125,21 +125,28 @@
         return get_dtype_cache(space).dtypes_by_name[self.byteorder + self.float_type]
 
     def descr_str(self, space):
-        if not self.is_record_type():
+        if not self.num == NPY.VOID:
             if self.char == 'S':
                 s = '|S' + str(self.get_size())
             else:
                 s = self.name
             return space.wrap(s)
+        elif self.subdtype is not None:
+            return space.str(space.newtuple([
+                self.subdtype.descr_get_str(space),
+                self.descr_get_shape(space)]))
         return space.str(self.descr_get_descr(space))
 
     def descr_repr(self, space):
-        if not self.is_record_type():
+        if not self.num == NPY.VOID:
             if self.char == 'S':
                 s = 'S' + str(self.get_size())
             else:
                 s = self.name
             r = space.wrap(s)
+        elif self.subdtype is not None:
+            r = space.newtuple([self.subdtype.descr_get_str(space),
+                                self.descr_get_shape(space)])
         else:
             r = self.descr_get_descr(space)
         return space.wrap("dtype(%s)" % space.str_w(space.repr(r)))
diff --git a/pypy/module/micronumpy/test/test_dtypes.py b/pypy/module/micronumpy/test/test_dtypes.py
--- a/pypy/module/micronumpy/test/test_dtypes.py
+++ b/pypy/module/micronumpy/test/test_dtypes.py
@@ -166,6 +166,9 @@
         d = dtype('S5')
         assert repr(d) == "dtype('S5')"
         assert str(d) == "|S5"
+        d = dtype(('<f8', 2))
+        assert repr(d) == "dtype(('<f8', (2,)))"
+        assert str(d) == "('<f8', (2,))"
 
     def test_bool_array(self):
         from numpypy import array, False_, True_
@@ -855,6 +858,7 @@
         assert dtype(('string', 7)).str == '|S7'
         assert dtype(('unicode', 7)).str == '<U7'
         assert dtype([('', 'f8')]).str == "|V8"
+        assert dtype(('f8', 2)).str == "|V16"
 
     def test_intp(self):
         from numpypy import dtype
@@ -927,6 +931,7 @@
         a = [('x', '<i8'), ('y', '<f8')]
         b = [('x', '<i4'), ('y', a)]
         assert np.dtype(b).descr == b
+        assert np.dtype(('<f8', 2)).descr == [('', '|V16')]
 
 class AppTestStrUnicodeDtypes(BaseNumpyAppTest):
     def test_mro(self):


More information about the pypy-commit mailing list