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

Method test_check_on_fields

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

Source from the content-addressed store, hash-verified

2118 assert_raises(TypeError, _check_fill_value, 'stuff', int)
2119
2120 def test_check_on_fields(self):
2121 # Tests _check_fill_value with records
2122 _check_fill_value = np.ma.core._check_fill_value
2123 ndtype = [('a', int), ('b', float), ('c', "|S3")]
2124 # A check on a list should return a single record
2125 fval = _check_fill_value([-999, -12345678.9, "???"], ndtype)
2126 assert_(isinstance(fval, ndarray))
2127 assert_equal(fval.item(), [-999, -12345678.9, b"???"])
2128 # A check on None should output the defaults
2129 fval = _check_fill_value(None, ndtype)
2130 assert_(isinstance(fval, ndarray))
2131 assert_equal(fval.item(), [default_fill_value(0),
2132 default_fill_value(0.),
2133 asbytes(default_fill_value("0"))])
2134 #.....Using a structured type as fill_value should work
2135 fill_val = np.array((-999, -12345678.9, "???"), dtype=ndtype)
2136 fval = _check_fill_value(fill_val, ndtype)
2137 assert_(isinstance(fval, ndarray))
2138 assert_equal(fval.item(), [-999, -12345678.9, b"???"])
2139
2140 #.....Using a flexible type w/ a different type shouldn't matter
2141 # BEHAVIOR in 1.5 and earlier, and 1.13 and later: match structured
2142 # types by position
2143 fill_val = np.array((-999, -12345678.9, "???"),
2144 dtype=[("A", int), ("B", float), ("C", "|S3")])
2145 fval = _check_fill_value(fill_val, ndtype)
2146 assert_(isinstance(fval, ndarray))
2147 assert_equal(fval.item(), [-999, -12345678.9, b"???"])
2148
2149 #.....Using an object-array shouldn't matter either
2150 fill_val = np.ndarray(shape=(1,), dtype=object)
2151 fill_val[0] = (-999, -12345678.9, b"???")
2152 fval = _check_fill_value(fill_val, object)
2153 assert_(isinstance(fval, ndarray))
2154 assert_equal(fval.item(), [-999, -12345678.9, b"???"])
2155 # NOTE: This test was never run properly as "fill_value" rather than
2156 # "fill_val" was assigned. Written properly, it fails.
2157 #fill_val = np.array((-999, -12345678.9, "???"))
2158 #fval = _check_fill_value(fill_val, ndtype)
2159 #assert_(isinstance(fval, ndarray))
2160 #assert_equal(fval.item(), [-999, -12345678.9, b"???"])
2161 #.....One-field-only flexible type should work as well
2162 ndtype = [("a", int)]
2163 fval = _check_fill_value(-999999999, ndtype)
2164 assert_(isinstance(fval, ndarray))
2165 assert_equal(fval.item(), (-999999999,))
2166
2167 def test_fillvalue_conversion(self):
2168 # Tests the behavior of fill_value during conversion

Callers

nothing calls this directly

Calls 6

assert_equalFunction · 0.90
default_fill_valueFunction · 0.90
asbytesFunction · 0.90
_check_fill_valueFunction · 0.85
itemMethod · 0.80
assert_Function · 0.50

Tested by

no test coverage detected