Commits

Brian Kearns  committed ff3d519

fix __array__ on subclasses of array

  • Participants
  • Parent commits a5313cb

Comments (0)

Files changed (2)

File pypy/module/micronumpy/interp_numarray.py

         if not space.is_none(w_dtype):
             raise OperationError(space.w_NotImplementedError, space.wrap(
                 "__array__(dtype) not implemented"))
-        # stub implementation of __array__()
-        return self
+        if type(self) is W_NDimArray:
+            return self
+        return W_NDimArray.from_shape_and_storage(
+            space, self.get_shape(), self.implementation.storage, self.get_dtype())
 
     def descr_array_iface(self, space):
         addr = self.implementation.get_storage_as_int(space)

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

         b[0]=100
         assert a[0,0] == 100
 
+        assert type(a) is not ndarray
+        assert a[0,0] == 100
+        b = a.__array__()
+        assert type(b) is ndarray
+        assert b[0,0] == 100
+
     def test_subtype_view(self):
         from numpypy import ndarray, array
         class matrix(ndarray):