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

Method test_copy

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

Source from the content-addressed store, hash-verified

397
398 @suppress_copy_mask_on_assignment
399 def test_copy(self):
400 # Tests of some subtle points of copying and sizing.
401 n = [0, 0, 1, 0, 0]
402 m = make_mask(n)
403 m2 = make_mask(m)
404 assert_(m is m2)
405 m3 = make_mask(m, copy=True)
406 assert_(m is not m3)
407
408 x1 = np.arange(5)
409 y1 = array(x1, mask=m)
410 assert_equal(y1._data.__array_interface__, x1.__array_interface__)
411 assert_(allequal(x1, y1.data))
412 assert_equal(y1._mask.__array_interface__, m.__array_interface__)
413
414 y1a = array(y1)
415 # Default for masked array is not to copy; see gh-10318.
416 assert_(y1a._data.__array_interface__ ==
417 y1._data.__array_interface__)
418 assert_(y1a._mask.__array_interface__ ==
419 y1._mask.__array_interface__)
420
421 y2 = array(x1, mask=m3)
422 assert_(y2._data.__array_interface__ == x1.__array_interface__)
423 assert_(y2._mask.__array_interface__ == m3.__array_interface__)
424 assert_(y2[2] is masked)
425 y2[2] = 9
426 assert_(y2[2] is not masked)
427 assert_(y2._mask.__array_interface__ == m3.__array_interface__)
428 assert_(allequal(y2.mask, 0))
429
430 y2a = array(x1, mask=m, copy=1)
431 assert_(y2a._data.__array_interface__ != x1.__array_interface__)
432 #assert_( y2a._mask is not m)
433 assert_(y2a._mask.__array_interface__ != m.__array_interface__)
434 assert_(y2a[2] is masked)
435 y2a[2] = 9
436 assert_(y2a[2] is not masked)
437 #assert_( y2a._mask is not m)
438 assert_(y2a._mask.__array_interface__ != m.__array_interface__)
439 assert_(allequal(y2a.mask, 0))
440
441 y3 = array(x1 * 1.0, mask=m)
442 assert_(filled(y3).dtype is (x1 * 1.0).dtype)
443
444 x4 = arange(4)
445 x4[2] = masked
446 y4 = resize(x4, (8,))
447 assert_equal(concatenate([x4, x4]), y4)
448 assert_equal(getmask(y4), [0, 0, 1, 0, 0, 0, 1, 0])
449 y5 = repeat(x4, (2, 2, 2, 2), axis=0)
450 assert_equal(y5, [0, 0, 1, 1, 2, 2, 3, 3])
451 y6 = repeat(x4, 2, axis=0)
452 assert_equal(y5, y6)
453 y7 = x4.repeat((2, 2, 2, 2), axis=0)
454 assert_equal(y5, y7)
455 y8 = x4.repeat(2, 0)
456 assert_equal(y5, y8)

Callers

nothing calls this directly

Calls 12

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
arangeFunction · 0.85
assert_Function · 0.50
copyMethod · 0.45

Tested by

no test coverage detected