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

Method test_drop_fields

numpy/lib/tests/test_recfunctions.py:65–95  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

63 ('b', [('ba', float), ('bb', int)])])]))
64
65 def test_drop_fields(self):
66 # Test drop_fields
67 a = np.array([(1, (2, 3.0)), (4, (5, 6.0))],
68 dtype=[('a', int), ('b', [('ba', float), ('bb', int)])])
69
70 # A basic field
71 test = drop_fields(a, 'a')
72 control = np.array([((2, 3.0),), ((5, 6.0),)],
73 dtype=[('b', [('ba', float), ('bb', int)])])
74 assert_equal(test, control)
75
76 # Another basic field (but nesting two fields)
77 test = drop_fields(a, 'b')
78 control = np.array([(1,), (4,)], dtype=[('a', int)])
79 assert_equal(test, control)
80
81 # A nested sub-field
82 test = drop_fields(a, ['ba', ])
83 control = np.array([(1, (3.0,)), (4, (6.0,))],
84 dtype=[('a', int), ('b', [('bb', int)])])
85 assert_equal(test, control)
86
87 # All the nested sub-field from a field: zap that field
88 test = drop_fields(a, ['ba', 'bb'])
89 control = np.array([(1,), (4,)], dtype=[('a', int)])
90 assert_equal(test, control)
91
92 # dropping all fields results in an array with no fields
93 test = drop_fields(a, ['a', 'b'])
94 control = np.array([(), ()], dtype=[])
95 assert_equal(test, control)
96
97 def test_rename_fields(self):
98 # Test rename fields

Callers

nothing calls this directly

Calls 2

drop_fieldsFunction · 0.90
assert_equalFunction · 0.90

Tested by

no test coverage detected