summaryrefslogtreecommitdiff
path: root/numpy/lib/tests/test_recfunctions.py
diff options
context:
space:
mode:
authorAllan Haldane <allan.haldane@gmail.com>2015-03-04 15:23:15 -0500
committerAllan Haldane <allan.haldane@gmail.com>2015-06-05 01:14:41 -0400
commite2cd6fa869cec6d92062fb687d8e6952c1202017 (patch)
tree8e0fe904c161e1122f0b6d3a3012fc84148354df /numpy/lib/tests/test_recfunctions.py
parent30d755d8737505717d54ed32501261bb94130a7f (diff)
downloadnumpy-e2cd6fa869cec6d92062fb687d8e6952c1202017.tar.gz
ENH: structured datatype safety checks
Previously views of structured arrays containing objects were completely disabled. This commit adds more lenient check for whether an object-array view is allowed, and adds similar checks to getfield/setfield Fixes #2346. Fixes #3256. Fixes #2599. Fixes #3253. Fixes #3286. Fixes #5762.
Diffstat (limited to 'numpy/lib/tests/test_recfunctions.py')
-rw-r--r--numpy/lib/tests/test_recfunctions.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_recfunctions.py b/numpy/lib/tests/test_recfunctions.py
index 51a2077eb..13e75cbd0 100644
--- a/numpy/lib/tests/test_recfunctions.py
+++ b/numpy/lib/tests/test_recfunctions.py
@@ -700,6 +700,36 @@ class TestJoinBy2(TestCase):
assert_equal(test.dtype, control.dtype)
assert_equal(test, control)
+class TestAppendFieldsObj(TestCase):
+ """
+ Test append_fields with arrays containing objects
+ """
+ # https://github.com/numpy/numpy/issues/2346
+
+ def setUp(self):
+ from datetime import date
+ self.data = dict(obj=date(2000, 1, 1))
+
+ def test_append_to_objects(self):
+ "Test append_fields when the base array contains objects"
+ obj = self.data['obj']
+ x = np.array([(obj, 1.), (obj, 2.)],
+ dtype=[('A', object), ('B', float)])
+ y = np.array([10, 20], dtype=int)
+ test = append_fields(x, 'C', data=y, usemask=False)
+ control = np.array([(obj, 1.0, 10), (obj, 2.0, 20)],
+ dtype=[('A', object), ('B', float), ('C', int)])
+ assert_equal(test, control)
+
+ def test_append_with_objects(self):
+ "Test append_fields when the appended data contains objects"
+ obj = self.data['obj']
+ x = np.array([(10, 1.), (20, 2.)], dtype=[('A', int), ('B', float)])
+ y = np.array([obj, obj], dtype=object)
+ test = append_fields(x, 'C', data=y, dtypes=object, usemask=False)
+ control = np.array([(10, 1.0, obj), (20, 2.0, obj)],
+ dtype=[('A', int), ('B', float), ('C', object)])
+ assert_equal(test, control)
if __name__ == '__main__':
run_module_suite()