MCPcopy
hub / github.com/numpy/numpy / test_copy

Method test_copy

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

Source from the content-addressed store, hash-verified

492
493 @pytest.mark.filterwarnings(WARNING_MARK_SPEC)
494 def test_copy(self):
495 # Tests of some subtle points of copying and sizing.
496 n = [0, 0, 1, 0, 0]
497 m = make_mask(n)
498 m2 = make_mask(m)
499 assert_(m is m2)
500 m3 = make_mask(m, copy=True)
501 assert_(m is not m3)
502
503 x1 = np.arange(5)
504 y1 = array(x1, mask=m)
505 assert_equal(y1._data.__array_interface__, x1.__array_interface__)
506 assert_(allequal(x1, y1.data))
507 assert_equal(y1._mask.__array_interface__, m.__array_interface__)
508
509 y1a = array(y1)
510 # Default for masked array is not to copy; see gh-10318.
511 assert_(y1a._data.__array_interface__ ==
512 y1._data.__array_interface__)
513 assert_(y1a._mask.__array_interface__ ==
514 y1._mask.__array_interface__)
515
516 y2 = array(x1, mask=m3)
517 assert_(y2._data.__array_interface__ == x1.__array_interface__)
518 assert_(y2._mask.__array_interface__ == m3.__array_interface__)
519 assert_(y2[2] is masked)
520 y2[2] = 9
521 assert_(y2[2] is not masked)
522 assert_(y2._mask.__array_interface__ == m3.__array_interface__)
523 assert_(allequal(y2.mask, 0))
524
525 y2a = array(x1, mask=m, copy=1)
526 assert_(y2a._data.__array_interface__ != x1.__array_interface__)
527 #assert_( y2a._mask is not m)
528 assert_(y2a._mask.__array_interface__ != m.__array_interface__)
529 assert_(y2a[2] is masked)
530 y2a[2] = 9
531 assert_(y2a[2] is not masked)
532 #assert_( y2a._mask is not m)
533 assert_(y2a._mask.__array_interface__ != m.__array_interface__)
534 assert_(allequal(y2a.mask, 0))
535
536 y3 = array(x1 * 1.0, mask=m)
537 assert_(filled(y3).dtype is (x1 * 1.0).dtype)
538
539 x4 = arange(4)
540 x4[2] = masked
541 y4 = resize(x4, (8,))
542 assert_equal(concatenate([x4, x4]), y4)
543 assert_equal(getmask(y4), [0, 0, 1, 0, 0, 0, 1, 0])
544 y5 = repeat(x4, (2, 2, 2, 2), axis=0)
545 assert_equal(y5, [0, 0, 1, 1, 2, 2, 3, 3])
546 y6 = repeat(x4, 2, axis=0)
547 assert_equal(y5, y6)
548 y7 = x4.repeat((2, 2, 2, 2), axis=0)
549 assert_equal(y5, y7)
550 y8 = x4.repeat(2, 0)
551 assert_equal(y5, y8)

Callers

nothing calls this directly

Calls 11

make_maskFunction · 0.90
arrayFunction · 0.90
assert_equalFunction · 0.90
allequalFunction · 0.90
filledFunction · 0.90
resizeFunction · 0.90
concatenateFunction · 0.90
getmaskFunction · 0.90
repeatFunction · 0.90
assert_Function · 0.85
copyMethod · 0.45

Tested by

no test coverage detected