MCPcopy Create free account
hub / github.com/numpy/numpy / test_flatten_structured_array

Method test_flatten_structured_array

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

Source from the content-addressed store, hash-verified

867 assert_equal(str(t_2d0), control)
868
869 def test_flatten_structured_array(self):
870 # Test flatten_structured_array on arrays
871 # On ndarray
872 ndtype = [('a', int), ('b', float)]
873 a = np.array([(1, 1), (2, 2)], dtype=ndtype)
874 test = flatten_structured_array(a)
875 control = np.array([[1., 1.], [2., 2.]], dtype=float)
876 assert_equal(test, control)
877 assert_equal(test.dtype, control.dtype)
878 # On masked_array
879 a = array([(1, 1), (2, 2)], mask=[(0, 1), (1, 0)], dtype=ndtype)
880 test = flatten_structured_array(a)
881 control = array([[1., 1.], [2., 2.]],
882 mask=[[0, 1], [1, 0]], dtype=float)
883 assert_equal(test, control)
884 assert_equal(test.dtype, control.dtype)
885 assert_equal(test.mask, control.mask)
886 # On masked array with nested structure
887 ndtype = [('a', int), ('b', [('ba', int), ('bb', float)])]
888 a = array([(1, (1, 1.1)), (2, (2, 2.2))],
889 mask=[(0, (1, 0)), (1, (0, 1))], dtype=ndtype)
890 test = flatten_structured_array(a)
891 control = array([[1., 1., 1.1], [2., 2., 2.2]],
892 mask=[[0, 1, 0], [1, 0, 1]], dtype=float)
893 assert_equal(test, control)
894 assert_equal(test.dtype, control.dtype)
895 assert_equal(test.mask, control.mask)
896 # Keeping the initial shape
897 ndtype = [('a', int), ('b', float)]
898 a = np.array([[(1, 1), ], [(2, 2), ]], dtype=ndtype)
899 test = flatten_structured_array(a)
900 control = np.array([[[1., 1.], ], [[2., 2.], ]], dtype=float)
901 assert_equal(test, control)
902 assert_equal(test.dtype, control.dtype)
903
904 def test_void0d(self):
905 # 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