MCPcopy Index your code
hub / github.com/numpy/numpy / test_flatten_structured_array

Method test_flatten_structured_array

numpy/ma/tests/test_core.py:967–1007  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

965 assert_equal(str(t_2d0), control)
966
967 def test_flatten_structured_array(self):
968 # Test flatten_structured_array on arrays
969 # On ndarray
970 ndtype = [('a', int), ('b', float)]
971 a = np.array([(1, 1), (2, 2)], dtype=ndtype)
972 test = flatten_structured_array(a)
973 control = np.array([[1., 1.], [2., 2.]], dtype=float)
974 assert_equal(test, control)
975 assert_equal(test.dtype, control.dtype)
976 # On masked_array
977 a = array([(1, 1), (2, 2)], mask=[(0, 1), (1, 0)], dtype=ndtype)
978 test = flatten_structured_array(a)
979 control = array([[1., 1.], [2., 2.]],
980 mask=[[0, 1], [1, 0]], dtype=float)
981 assert_equal(test, control)
982 assert_equal(test.dtype, control.dtype)
983 assert_equal(test.mask, control.mask)
984 # On masked array with nested structure
985 ndtype = [('a', int), ('b', [('ba', int), ('bb', float)])]
986 a = array([(1, (1, 1.1)), (2, (2, 2.2))],
987 mask=[(0, (1, 0)), (1, (0, 1))], dtype=ndtype)
988 test = flatten_structured_array(a)
989 control = array([[1., 1., 1.1], [2., 2., 2.2]],
990 mask=[[0, 1, 0], [1, 0, 1]], dtype=float)
991 assert_equal(test, control)
992 assert_equal(test.dtype, control.dtype)
993 assert_equal(test.mask, control.mask)
994 # Keeping the initial shape
995 ndtype = [('a', int), ('b', float)]
996 a = np.array([[(1, 1), ], [(2, 2), ]], dtype=ndtype)
997 test = flatten_structured_array(a)
998 control = np.array([[[1., 1.], ], [[2., 2.], ]], dtype=float)
999 assert_equal(test, control)
1000 assert_equal(test.dtype, control.dtype)
1001 # for strings
1002 ndtype = [('a', 'U5'), ('b', [('c', 'U5')])]
1003 arr = np.array([('NumPy', ('array',)), ('array', ('numpy',))], dtype=ndtype)
1004 test = flatten_structured_array(arr)
1005 control = np.array([['NumPy', 'array'], ['array', 'numpy']], dtype='U5')
1006 assert_equal(test, control)
1007 assert_equal(test.dtype, control.dtype)
1008
1009 def test_void0d(self):
1010 # Test creating a mvoid object

Callers

nothing calls this directly

Calls 3

flatten_structured_arrayFunction · 0.90
assert_equalFunction · 0.90
arrayFunction · 0.90

Tested by

no test coverage detected