Skip to content

Commit

Permalink
Merge pull request numpy#2746 from GaelVaroquaux/fix-470
Browse files Browse the repository at this point in the history
FIX: base always refers to the original subclass
  • Loading branch information
certik committed Dec 4, 2012
2 parents d0c0f14 + 69d57d0 commit d8370da
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 4 additions & 4 deletions numpy/core/src/multiarray/arrayobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ PyArray_SetUpdateIfCopyBase(PyArrayObject *arr, PyArrayObject *base)
/*
* Unlike PyArray_SetBaseObject, we do not compress the chain of base
* references.
*/
*/
((PyArrayObject_fields *)arr)->base = (PyObject *)base;
PyArray_ENABLEFLAGS(arr, NPY_ARRAY_UPDATEIFCOPY);
PyArray_CLEARFLAGS(base, NPY_ARRAY_WRITEABLE);
Expand Down Expand Up @@ -168,10 +168,10 @@ PyArray_SetBaseObject(PyArrayObject *arr, PyObject *obj)
if (tmp == NULL) {
break;
}
/* Stop the collapse for array sub-classes if new base
* would not be of the same type.
/* Stop the collapse new base when the would not be of the same
* type (i.e. different subclass).
*/
if (!(PyArray_CheckExact(arr)) & (Py_TYPE(tmp) != Py_TYPE(arr))) {
if (Py_TYPE(tmp) != Py_TYPE(arr)) {
break;
}

Expand Down
4 changes: 3 additions & 1 deletion numpy/core/tests/test_memmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os

from numpy import memmap
from numpy import arange, allclose
from numpy import arange, allclose, asarray
from numpy.testing import *

class TestMemmap(TestCase):
Expand Down Expand Up @@ -112,6 +112,8 @@ def test_view(self):
new2 = new1.view()
assert(new1.base is fp)
assert(new2.base is fp)
new_array = asarray(fp)
assert(new_array.base is fp)

if __name__ == "__main__":
run_module_suite()

0 comments on commit d8370da

Please sign in to comment.