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

Method test_make_mask

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

Source from the content-addressed store, hash-verified

4991 assert_(test.fields['b'][0] is base_mtype)
4992
4993 def test_make_mask(self):
4994 # Test make_mask
4995 # w/ a list as an input
4996 mask = [0, 1]
4997 test = make_mask(mask)
4998 assert_equal(test.dtype, MaskType)
4999 assert_equal(test, [0, 1])
5000 # w/ a ndarray as an input
5001 mask = np.array([0, 1], dtype=bool)
5002 test = make_mask(mask)
5003 assert_equal(test.dtype, MaskType)
5004 assert_equal(test, [0, 1])
5005 # w/ a flexible-type ndarray as an input - use default
5006 mdtype = [('a', bool), ('b', bool)]
5007 mask = np.array([(0, 0), (0, 1)], dtype=mdtype)
5008 test = make_mask(mask)
5009 assert_equal(test.dtype, MaskType)
5010 assert_equal(test, [1, 1])
5011 # w/ a flexible-type ndarray as an input - use input dtype
5012 mdtype = [('a', bool), ('b', bool)]
5013 mask = np.array([(0, 0), (0, 1)], dtype=mdtype)
5014 test = make_mask(mask, dtype=mask.dtype)
5015 assert_equal(test.dtype, mdtype)
5016 assert_equal(test, mask)
5017 # w/ a flexible-type ndarray as an input - use input dtype
5018 mdtype = [('a', float), ('b', float)]
5019 bdtype = [('a', bool), ('b', bool)]
5020 mask = np.array([(0, 0), (0, 1)], dtype=mdtype)
5021 test = make_mask(mask, dtype=mask.dtype)
5022 assert_equal(test.dtype, bdtype)
5023 assert_equal(test, np.array([(0, 0), (0, 1)], dtype=bdtype))
5024 # Ensure this also works for void
5025 mask = np.array((False, True), dtype='?,?')[()]
5026 assert_(isinstance(mask, np.void))
5027 test = make_mask(mask, dtype=mask.dtype)
5028 assert_equal(test, mask)
5029 assert_(test is not mask)
5030 mask = np.array((0, 1), dtype='i4,i4')[()]
5031 test2 = make_mask(mask, dtype=mask.dtype)
5032 assert_equal(test2, test)
5033 # test that nomask is returned when m is nomask.
5034 bools = [True, False]
5035 dtypes = [MaskType, float]
5036 msgformat = 'copy=%s, shrink=%s, dtype=%s'
5037 for cpy, shr, dtype in itertools.product(bools, bools, dtypes):
5038 res = make_mask(nomask, copy=cpy, shrink=shr, dtype=dtype)
5039 assert_(res is nomask, msgformat % (cpy, shr, dtype))
5040
5041 def test_mask_or(self):
5042 # Initialize

Callers

nothing calls this directly

Calls 3

make_maskFunction · 0.90
assert_equalFunction · 0.90
assert_Function · 0.85

Tested by

no test coverage detected