diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2015-11-06 11:21:22 -0700 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2015-11-06 11:21:22 -0700 |
commit | 9cc7bc3ad4e3e95f76ec1036adf45990d204a756 (patch) | |
tree | 4779b52a2af092c9d2d73e1d563befed608d0789 /numpy/core | |
parent | cdef8d3e408899f7e0cc1037d358ece8d9cc3324 (diff) | |
parent | c06726daa4d57893bc6132c3f311bd14ec6dc110 (diff) | |
download | numpy-9cc7bc3ad4e3e95f76ec1036adf45990d204a756.tar.gz |
Merge pull request #6643 from ahaldane/recarray_getitem_returns_recarray
ENH: make recarray.getitem return a recarray
Diffstat (limited to 'numpy/core')
-rw-r--r-- | numpy/core/records.py | 1 | ||||
-rw-r--r-- | numpy/core/tests/test_records.py | 8 |
2 files changed, 9 insertions, 0 deletions
diff --git a/numpy/core/records.py b/numpy/core/records.py index 4ce3fe98a..b07755384 100644 --- a/numpy/core/records.py +++ b/numpy/core/records.py @@ -502,6 +502,7 @@ class recarray(ndarray): # we might also be returning a single element if isinstance(obj, ndarray): if obj.dtype.fields: + obj = obj.view(recarray) if issubclass(obj.dtype.type, nt.void): return obj.view(dtype=(self.dtype.type, obj.dtype)) return obj diff --git a/numpy/core/tests/test_records.py b/numpy/core/tests/test_records.py index 290bc4fa7..e0f0a3a8f 100644 --- a/numpy/core/tests/test_records.py +++ b/numpy/core/tests/test_records.py @@ -121,6 +121,14 @@ class TestFromrecords(TestCase): assert_equal(type(rv), np.recarray) assert_equal(rv.dtype.type, np.record) + #check that getitem also preserves np.recarray and np.record + r = np.rec.array(np.ones(4, dtype=[('a', 'i4'), ('b', 'i4'), + ('c', 'i4,i4')])) + assert_equal(r['c'].dtype.type, np.record) + assert_equal(type(r['c']), np.recarray) + assert_equal(r[['a', 'b']].dtype.type, np.record) + assert_equal(type(r[['a', 'b']]), np.recarray) + # check that accessing nested structures keep record type, but # not for subarrays, non-void structures, non-structured voids test_dtype = [('a', 'f4,f4'), ('b', 'V8'), ('c', ('f4',2)), |