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

Method test_check_on_fields

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

Source from the content-addressed store, hash-verified

2315 assert res['foo'] == np.datetime64(42, 'D')
2316
2317 def test_check_on_fields(self):
2318 # Tests _check_fill_value with records
2319 _check_fill_value = np.ma.core._check_fill_value
2320 ndtype = [('a', int), ('b', float), ('c', "|S3")]
2321 # A check on a list should return a single record
2322 fval = _check_fill_value([-999, -12345678.9, "???"], ndtype)
2323 assert_(isinstance(fval, ndarray))
2324 assert_equal(fval.item(), [-999, -12345678.9, b"???"])
2325 # A check on None should output the defaults
2326 fval = _check_fill_value(None, ndtype)
2327 assert_(isinstance(fval, ndarray))
2328 assert_equal(fval.item(), [default_fill_value(0),
2329 default_fill_value(0.),
2330 asbytes(default_fill_value("0"))])
2331 #.....Using a structured type as fill_value should work
2332 fill_val = np.array((-999, -12345678.9, "???"), dtype=ndtype)
2333 fval = _check_fill_value(fill_val, ndtype)
2334 assert_(isinstance(fval, ndarray))
2335 assert_equal(fval.item(), [-999, -12345678.9, b"???"])
2336
2337 #.....Using a flexible type w/ a different type shouldn't matter
2338 # BEHAVIOR in 1.5 and earlier, and 1.13 and later: match structured
2339 # types by position
2340 fill_val = np.array((-999, -12345678.9, "???"),
2341 dtype=[("A", int), ("B", float), ("C", "|S3")])
2342 fval = _check_fill_value(fill_val, ndtype)
2343 assert_(isinstance(fval, ndarray))
2344 assert_equal(fval.item(), [-999, -12345678.9, b"???"])
2345
2346 #.....Using an object-array shouldn't matter either
2347 fill_val = np.ndarray(shape=(1,), dtype=object)
2348 fill_val[0] = (-999, -12345678.9, b"???")
2349 fval = _check_fill_value(fill_val, object)
2350 assert_(isinstance(fval, ndarray))
2351 assert_equal(fval.item(), [-999, -12345678.9, b"???"])
2352 # NOTE: This test was never run properly as "fill_value" rather than
2353 # "fill_val" was assigned. Written properly, it fails.
2354 #fill_val = np.array((-999, -12345678.9, "???"))
2355 #fval = _check_fill_value(fill_val, ndtype)
2356 #assert_(isinstance(fval, ndarray))
2357 #assert_equal(fval.item(), [-999, -12345678.9, b"???"])
2358 #.....One-field-only flexible type should work as well
2359 ndtype = [("a", int)]
2360 fval = _check_fill_value(-999999999, ndtype)
2361 assert_(isinstance(fval, ndarray))
2362 assert_equal(fval.item(), (-999999999,))
2363
2364 def test_fillvalue_conversion(self):
2365 # 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
assert_Function · 0.85
itemMethod · 0.80

Tested by

no test coverage detected