Author: Brian Kearns <[email protected]>
Branch:
Changeset: r68415:ff3d519d9557
Date: 2013-12-13 00:17 -0500
http://bitbucket.org/pypy/pypy/changeset/ff3d519d9557/
Log: fix __array__ on subclasses of array
diff --git a/pypy/module/micronumpy/interp_numarray.py
b/pypy/module/micronumpy/interp_numarray.py
--- a/pypy/module/micronumpy/interp_numarray.py
+++ b/pypy/module/micronumpy/interp_numarray.py
@@ -493,8 +493,10 @@
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)
diff --git a/pypy/module/micronumpy/test/test_subtype.py
b/pypy/module/micronumpy/test/test_subtype.py
--- a/pypy/module/micronumpy/test/test_subtype.py
+++ b/pypy/module/micronumpy/test/test_subtype.py
@@ -50,6 +50,12 @@
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):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit