summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjayvius <jay.bourque@continuum.io>2012-07-12 13:37:28 -0500
committerJay Bourque <jay.bourque@continuum.io>2012-07-17 16:05:10 -0500
commit0c09e1f184fde335f3533b0b9ef6ea46379309db (patch)
tree9ce5e71a40fdae4e7d1cedc86d0c523c1213ebf7
parent6363bb7cbb1d0e292e8af87f92a28faf781d3d95 (diff)
downloadnumpy-0c09e1f184fde335f3533b0b9ef6ea46379309db.tar.gz
fix previous commit to return copy of view instead of view
-rw-r--r--numpy/core/_internal.py17
-rw-r--r--numpy/core/src/multiarray/mapping.c5
2 files changed, 8 insertions, 14 deletions
diff --git a/numpy/core/_internal.py b/numpy/core/_internal.py
index 29d21a9bc..88a41fd0d 100644
--- a/numpy/core/_internal.py
+++ b/numpy/core/_internal.py
@@ -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
diff --git a/numpy/core/src/multiarray/mapping.c b/numpy/core/src/multiarray/mapping.c
index b2643f89f..663a3ef7f 100644
--- a/numpy/core/src/multiarray/mapping.c
+++ b/numpy/core/src/multiarray/mapping.c
@@ -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;
}
}