MCPcopy
hub / github.com/numpy/numpy / test_indexing

Method test_indexing

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

Source from the content-addressed store, hash-verified

423 assert_(a[0] is dt)
424
425 def test_indexing(self):
426 # Tests conversions and indexing
427 x1 = np.array([1, 2, 4, 3])
428 x2 = array(x1, mask=[1, 0, 0, 0])
429 x3 = array(x1, mask=[0, 1, 0, 1])
430 x4 = array(x1)
431 # test conversion to strings
432 str(x2) # raises?
433 repr(x2) # raises?
434 assert_equal(np.sort(x1), sort(x2, endwith=False))
435 # tests of indexing
436 assert_(type(x2[1]) is type(x1[1]))
437 assert_(x1[1] == x2[1])
438 assert_(x2[0] is masked)
439 assert_equal(x1[2], x2[2])
440 assert_equal(x1[2:5], x2[2:5])
441 assert_equal(x1[:], x2[:])
442 assert_equal(x1[1:], x3[1:])
443 x1[2] = 9
444 x2[2] = 9
445 assert_equal(x1, x2)
446 x1[1:3] = 99
447 x2[1:3] = 99
448 assert_equal(x1, x2)
449 x2[1] = masked
450 assert_equal(x1, x2)
451 x2[1:3] = masked
452 assert_equal(x1, x2)
453 x2[:] = x1
454 x2[1] = masked
455 assert_(allequal(getmask(x2), array([0, 1, 0, 0])))
456 x3[:] = masked_array([1, 2, 3, 4], [0, 1, 1, 0])
457 assert_(allequal(getmask(x3), array([0, 1, 1, 0])))
458 x4[:] = masked_array([1, 2, 3, 4], [0, 1, 1, 0])
459 assert_(allequal(getmask(x4), array([0, 1, 1, 0])))
460 assert_(allequal(x4, array([1, 2, 3, 4])))
461 x1 = np.arange(5) * 1.0
462 x2 = masked_values(x1, 3.0)
463 assert_equal(x1, x2)
464 assert_(allequal(array([0, 0, 0, 1, 0], MaskType), x2.mask))
465 assert_equal(3.0, x2.fill_value)
466 x1 = array([1, 'hello', 2, 3], object)
467 x2 = np.array([1, 'hello', 2, 3], object)
468 s1 = x1[1]
469 s2 = x2[1]
470 assert_equal(type(s2), str)
471 assert_equal(type(s1), str)
472 assert_equal(s1, s2)
473 assert_(x1[1:1].shape == (0,))
474
475 def test_setitem_no_warning(self):
476 # Setitem shouldn't warn, because the assignment might be masked

Callers

nothing calls this directly

Calls 8

arrayFunction · 0.90
assert_equalFunction · 0.90
sortFunction · 0.90
allequalFunction · 0.90
getmaskFunction · 0.90
masked_valuesFunction · 0.90
assert_Function · 0.85
sortMethod · 0.45

Tested by

no test coverage detected