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

Method test_make_mask

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

Source from the content-addressed store, hash-verified

4764 assert_(test.fields['b'][0] is base_mtype)
4765
4766 def test_make_mask(self):
4767 # Test make_mask
4768 # w/ a list as an input
4769 mask = [0, 1]
4770 test = make_mask(mask)
4771 assert_equal(test.dtype, MaskType)
4772 assert_equal(test, [0, 1])
4773 # w/ a ndarray as an input
4774 mask = np.array([0, 1], dtype=bool)
4775 test = make_mask(mask)
4776 assert_equal(test.dtype, MaskType)
4777 assert_equal(test, [0, 1])
4778 # w/ a flexible-type ndarray as an input - use default
4779 mdtype = [('a', bool), ('b', bool)]
4780 mask = np.array([(0, 0), (0, 1)], dtype=mdtype)
4781 test = make_mask(mask)
4782 assert_equal(test.dtype, MaskType)
4783 assert_equal(test, [1, 1])
4784 # w/ a flexible-type ndarray as an input - use input dtype
4785 mdtype = [('a', bool), ('b', bool)]
4786 mask = np.array([(0, 0), (0, 1)], dtype=mdtype)
4787 test = make_mask(mask, dtype=mask.dtype)
4788 assert_equal(test.dtype, mdtype)
4789 assert_equal(test, mask)
4790 # w/ a flexible-type ndarray as an input - use input dtype
4791 mdtype = [('a', float), ('b', float)]
4792 bdtype = [('a', bool), ('b', bool)]
4793 mask = np.array([(0, 0), (0, 1)], dtype=mdtype)
4794 test = make_mask(mask, dtype=mask.dtype)
4795 assert_equal(test.dtype, bdtype)
4796 assert_equal(test, np.array([(0, 0), (0, 1)], dtype=bdtype))
4797 # Ensure this also works for void
4798 mask = np.array((False, True), dtype='?,?')[()]
4799 assert_(isinstance(mask, np.void))
4800 test = make_mask(mask, dtype=mask.dtype)
4801 assert_equal(test, mask)
4802 assert_(test is not mask)
4803 mask = np.array((0, 1), dtype='i4,i4')[()]
4804 test2 = make_mask(mask, dtype=mask.dtype)
4805 assert_equal(test2, test)
4806 # test that nomask is returned when m is nomask.
4807 bools = [True, False]
4808 dtypes = [MaskType, float]
4809 msgformat = 'copy=%s, shrink=%s, dtype=%s'
4810 for cpy, shr, dt in itertools.product(bools, bools, dtypes):
4811 res = make_mask(nomask, copy=cpy, shrink=shr, dtype=dt)
4812 assert_(res is nomask, msgformat % (cpy, shr, dt))
4813
4814 def test_mask_or(self):
4815 # Initialize

Callers

nothing calls this directly

Calls 3

make_maskFunction · 0.90
assert_equalFunction · 0.90
assert_Function · 0.50

Tested by

no test coverage detected