Author: Brian Kearns <[email protected]>
Branch: 
Changeset: r67966:5dc341236760
Date: 2013-11-11 20:37 -0500
http://bitbucket.org/pypy/pypy/changeset/5dc341236760/

Log:    test/fix some numpy dtype creation from tuple 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
@@ -382,7 +382,14 @@
     elif space.isinstance_w(w_dtype, space.w_list):
         return dtype_from_list(space, w_dtype)
     elif space.isinstance_w(w_dtype, space.w_tuple):
-        return descr__new__(space, w_subtype, space.getitem(w_dtype, 
space.wrap(0)), w_align, w_copy, w_shape=space.getitem(w_dtype, space.wrap(1)))
+        w_dtype0 = space.getitem(w_dtype, space.wrap(0))
+        w_dtype1 = space.getitem(w_dtype, space.wrap(1))
+        subdtype = descr__new__(space, w_subtype, w_dtype0, w_align, w_copy)
+        assert isinstance(subdtype, W_Dtype)
+        if subdtype.get_size() == 0:
+            name = "%s%d" % (subdtype.kind, space.int_w(w_dtype1))
+            return descr__new__(space, w_subtype, space.wrap(name), w_align, 
w_copy)
+        return descr__new__(space, w_subtype, w_dtype0, w_align, w_copy, 
w_shape=w_dtype1)
     elif space.isinstance_w(w_dtype, space.w_dict):
         return dtype_from_dict(space, w_dtype)
     for dtype in cache.builtin_dtypes:
diff --git a/pypy/module/micronumpy/test/dummy_module.py 
b/pypy/module/micronumpy/test/dummy_module.py
--- a/pypy/module/micronumpy/test/dummy_module.py
+++ b/pypy/module/micronumpy/test/dummy_module.py
@@ -20,7 +20,7 @@
 for t in types:
     globals()[t] = dtype(t).type
 
-types = ['bool', 'int', 'float', 'complex', 'str', 'unicode']
+types = ['bool', 'int', 'float', 'complex', 'str', 'string', 'unicode']
 for t in types:
     globals()[t + '_'] = dtype(t).type
 del types
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
@@ -46,6 +46,18 @@
         assert 'data type not understood' in str(exc.value)
         raises(KeyError, 'dtype(int)["asdasd"]')
 
+    def test_dtype_from_tuple(self):
+        import numpy as np
+        d = np.dtype((np.int64, 4))
+        assert d == np.dtype(('i8', (4,)))
+        assert d.shape == (4,)
+        d = np.dtype((np.string_, 4))
+        assert d == np.dtype('S4')
+        assert d.shape == ()
+        d = np.dtype(('S', 4))
+        assert d == np.dtype('S4')
+        assert d.shape == ()
+
     def test_dtype_eq(self):
         from numpypy import dtype
 
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to