summaryrefslogtreecommitdiff
path: root/numpy/core
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/core')
-rw-r--r--numpy/core/records.py1
-rw-r--r--numpy/core/tests/test_records.py8
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)),