Commits

Brian Kearns committed 31e1428

more view tests/fixes

  • Participants
  • Parent commits 014e37c

Comments (0)

Files changed (4)

File pypy/module/micronumpy/arrayimpl/scalar.py

         scalar = Scalar(dtype)
         if dtype.is_str_or_unicode():
             scalar.value = dtype.coerce(space, space.wrap(self.value.raw_str()))
+        elif dtype.is_record_type():
+            raise OperationError(space.w_NotImplementedError, space.wrap(
+                "viewing scalar as record not implemented"))
         else:
             scalar.value = dtype.itemtype.runpack_str(self.value.raw_str())
         return scalar

File pypy/module/micronumpy/interp_boxes.py

                 "new type not compatible with array."))
         if dtype.is_str_or_unicode():
             return dtype.coerce(space, space.wrap(self.raw_str()))
+        elif dtype.is_record_type():
+            raise OperationError(space.w_NotImplementedError, space.wrap(
+                "viewing scalar as record not implemented"))
         else:
             return dtype.itemtype.runpack_str(self.raw_str())
 

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

         assert a.view('S4') == '\x03'
         a = array('abc1', dtype='c')
         assert a.view('S4') == 'abc1'
+        import sys
+        if '__pypy__' in sys.builtin_module_names:
+            raises(NotImplementedError, a.view, [('a', 'i2'), ('b', 'i2')])
+        else:
+            b = a.view([('a', 'i2'), ('b', 'i2')])
+            assert b.shape == (1,)
+            assert b[0][0] == 25185
+            assert b[0][1] == 12643
         a = array([(1, 2)], dtype=[('a', int), ('b', int)])[0]
         assert a.shape == ()
         assert a.view('S16') == '\x01' + '\x00' * 7 + '\x02'

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

 
     def test_view(self):
         import numpy as np
+        import sys
         s = np.dtype('int64').type(12)
         exc = raises(ValueError, s.view, 'int8')
         assert exc.value[0] == "new type not compatible with array."
         assert t == '\x0c'
         s = np.dtype('string').type('abc1')
         assert s.view('S4') == 'abc1'
+        if '__pypy__' in sys.builtin_module_names:
+            raises(NotImplementedError, s.view, [('a', 'i2'), ('b', 'i2')])
+        else:
+            b = s.view([('a', 'i2'), ('b', 'i2')])
+            assert b.shape == ()
+            assert b[0] == 25185
+            assert b[1] == 12643
+        if '__pypy__' in sys.builtin_module_names:
+            raises(TypeError, "np.dtype([('a', int), ('b', int)]).type('a' * 16)")
+        else:
+            s = np.dtype([('a', int), ('b', int)]).type('a' * 16)
+            assert s.view('S16') == 'a' * 16
 
     def test_complex_scalar_complex_cast(self):
         import numpy as np