summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjayvius <jay.bourque@continuum.io>2012-07-12 13:35:52 -0500
committerJay Bourque <jay.bourque@continuum.io>2012-07-17 16:05:10 -0500
commit6363bb7cbb1d0e292e8af87f92a28faf781d3d95 (patch)
treeb588098a81fc7a9483f818640c9df8ae85211805
parent6c772fab57934d24b66638ea5001eb02d1662f5e (diff)
downloadnumpy-6363bb7cbb1d0e292e8af87f92a28faf781d3d95.tar.gz
Add ability to get view when selecting subset of fields.
Add ability to get view when selecting subset of fields in a struct array, for numpy 1.8.0. Currently a copy is still returned - set WARN_ON_WRITE flag which will be removed in a future version of numpy.
-rw-r--r--numpy/core/_internal.py7
-rw-r--r--numpy/core/src/multiarray/mapping.c1
2 files changed, 8 insertions, 0 deletions
diff --git a/numpy/core/_internal.py b/numpy/core/_internal.py
index 309b53c44..29d21a9bc 100644
--- a/numpy/core/_internal.py
+++ b/numpy/core/_internal.py
@@ -298,6 +298,13 @@ def _index_fields(ary, fields):
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]
+ offsets = [dt.fields[name][1] for name in fields if name in dt.names]
+
+ view_dtype = {'names':names, 'formats':formats, 'offsets':offsets}
+ view = ary.view(dtype=view_dtype)
+
return newarray
# Given a string containing a PEP 3118 format specifier,
diff --git a/numpy/core/src/multiarray/mapping.c b/numpy/core/src/multiarray/mapping.c
index cdefb9982..b2643f89f 100644
--- a/numpy/core/src/multiarray/mapping.c
+++ b/numpy/core/src/multiarray/mapping.c
@@ -975,6 +975,7 @@ 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);
return obj;
}