1. Pypy
  2. Untitled project
  3. pypy

Commits

Brian Kearns  committed 5dc3412

test/fix some numpy dtype creation from tuple cases

  • Participants
  • Parent commits 261e5f9
  • Branches default

Comments (0)

Files changed (3)

File pypy/module/micronumpy/interp_dtype.py

View file
  • Ignore whitespace
     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:

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

View file
  • Ignore whitespace
 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

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

View file
  • Ignore whitespace
         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