Skip to content

Commit e4fe789

Browse files
committed
FIX: base always refers to the original subclass
Closes numpy#470 The use case is that if b is a memmap, 'np.asarray(b).base' should be a memmap, and thus we put is to b in such a situation.
1 parent 3418ffc commit e4fe789

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

‎numpy/core/src/multiarray/arrayobject.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,10 @@ PyArray_SetBaseObject(PyArrayObject *arr, PyObject *obj)
168168
if (tmp == NULL) {
169169
break;
170170
}
171-
/* Stop the collapse for array sub-classes if new base
172-
* would not be of the same type.
171+
/* Stop the collapse new base would not be of the same type (i.e.
172+
* different subclass).
173173
*/
174-
if (!(PyArray_CheckExact(arr)) & (Py_TYPE(tmp) != Py_TYPE(arr))) {
174+
if (Py_TYPE(tmp) != Py_TYPE(arr)) {
175175
break;
176176
}
177177

‎numpy/core/tests/test_memmap.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import os
44

55
from numpy import memmap
6-
from numpy import arange, allclose
6+
from numpy import arange, allclose, asarray
77
from numpy.testing import *
88

99
class TestMemmap(TestCase):
@@ -112,6 +112,8 @@ def test_view(self):
112112
new2 = new1.view()
113113
assert(new1.base is fp)
114114
assert(new2.base is fp)
115+
new_array = asarray(fp)
116+
assert(new_array.base is fp)
115117

116118
if __name__ == "__main__":
117119
run_module_suite()

0 commit comments

Comments
 (0)