Skip to content

Commit

Permalink
fix previous commit to return copy of view instead of view
Browse files Browse the repository at this point in the history
  • Loading branch information
jayvius committed Jul 17, 2012
1 parent 6363bb7 commit 0c09e1f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
17 changes: 4 additions & 13 deletions numpy/core/_internal.py
Expand Up @@ -286,26 +286,17 @@ def _newnames(datatype, order):
# construct a new array with just those fields copied over
def _index_fields(ary, fields):
from multiarray import empty, dtype
from numpy import copy
dt = ary.dtype
new_dtype = [(name, dt[name]) for name in fields if name in dt.names]
if ary.flags.f_contiguous:
order = 'F'
else:
order = 'C'

newarray = empty(ary.shape, dtype=new_dtype, order=order)

for name in fields:
newarray[name] = ary[name]

names = [name for name in fields if name in dt.names]
formats = dt.fields[name][0] for name in fields if name in dt.names]
formats = [dt.fields[name][0] for name in fields if name in dt.names]
offsets = [dt.fields[name][1] for name in fields if name in dt.names]

view_dtype = {'names':names, 'formats':formats, 'offsets':offsets}
view_dtype = {'names':names, 'formats':formats, 'offsets':offsets, 'itemsize':dt.itemsize}
view = ary.view(dtype=view_dtype)

return newarray
return copy(view)

# Given a string containing a PEP 3118 format specifier,
# construct a Numpy dtype
Expand Down
5 changes: 4 additions & 1 deletion numpy/core/src/multiarray/mapping.c
Expand Up @@ -975,8 +975,11 @@ array_subscript(PyArrayObject *self, PyObject *op)
}
obj = PyObject_CallMethod(_numpy_internal,
"_index_fields", "OO", self, op);
PyArray_ENABLEFLAGS((PyArrayObject*)obj, NPY_ARRAY_WARN_ON_WRITE);
Py_DECREF(_numpy_internal);
if (obj == NULL) {
return NULL;
}
PyArray_ENABLEFLAGS((PyArrayObject*)obj, NPY_ARRAY_WARN_ON_WRITE);
return obj;
}
}
Expand Down

0 comments on commit 0c09e1f

Please sign in to comment.