MCPcopy
hub / github.com/numpy/numpy / test_put

Method test_put

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

Source from the content-addressed store, hash-verified

3573
3574 @pytest.mark.filterwarnings(WARNING_MARK_SPEC)
3575 def test_put(self):
3576 # Tests put.
3577 d = arange(5)
3578 n = [0, 0, 0, 1, 1]
3579 m = make_mask(n)
3580 x = array(d, mask=m)
3581 assert_(x[3] is masked)
3582 assert_(x[4] is masked)
3583 x[[1, 4]] = [10, 40]
3584 assert_(x[3] is masked)
3585 assert_(x[4] is not masked)
3586 assert_equal(x, [0, 10, 2, -1, 40])
3587
3588 x = masked_array(arange(10), mask=[1, 0, 0, 0, 0] * 2)
3589 i = [0, 2, 4, 6]
3590 x.put(i, [6, 4, 2, 0])
3591 assert_equal(x, asarray([6, 1, 4, 3, 2, 5, 0, 7, 8, 9, ]))
3592 assert_equal(x.mask, [0, 0, 0, 0, 0, 1, 0, 0, 0, 0])
3593 x.put(i, masked_array([0, 2, 4, 6], [1, 0, 1, 0]))
3594 assert_array_equal(x, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ])
3595 assert_equal(x.mask, [1, 0, 0, 0, 1, 1, 0, 0, 0, 0])
3596
3597 x = masked_array(arange(10), mask=[1, 0, 0, 0, 0] * 2)
3598 put(x, i, [6, 4, 2, 0])
3599 assert_equal(x, asarray([6, 1, 4, 3, 2, 5, 0, 7, 8, 9, ]))
3600 assert_equal(x.mask, [0, 0, 0, 0, 0, 1, 0, 0, 0, 0])
3601 put(x, i, masked_array([0, 2, 4, 6], [1, 0, 1, 0]))
3602 assert_array_equal(x, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ])
3603 assert_equal(x.mask, [1, 0, 0, 0, 1, 1, 0, 0, 0, 0])
3604
3605 def test_put_nomask(self):
3606 # GitHub issue 6425

Callers

nothing calls this directly

Calls 8

make_maskFunction · 0.90
arrayFunction · 0.90
assert_equalFunction · 0.90
asarrayFunction · 0.90
assert_array_equalFunction · 0.90
putFunction · 0.90
assert_Function · 0.85
putMethod · 0.80

Tested by

no test coverage detected