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

Method test_sort

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

Source from the content-addressed store, hash-verified

3492 assert_equal(x._mask.shape, (4,))
3493
3494 def test_sort(self):
3495 # Test sort
3496 x = array([1, 4, 2, 3], mask=[0, 1, 0, 0], dtype=np.uint8)
3497
3498 sortedx = sort(x)
3499 assert_equal(sortedx._data, [1, 2, 3, 4])
3500 assert_equal(sortedx._mask, [0, 0, 0, 1])
3501
3502 sortedx = sort(x, endwith=False)
3503 assert_equal(sortedx._data, [4, 1, 2, 3])
3504 assert_equal(sortedx._mask, [1, 0, 0, 0])
3505
3506 x.sort()
3507 assert_equal(x._data, [1, 2, 3, 4])
3508 assert_equal(x._mask, [0, 0, 0, 1])
3509
3510 x = array([1, 4, 2, 3], mask=[0, 1, 0, 0], dtype=np.uint8)
3511 x.sort(endwith=False)
3512 assert_equal(x._data, [4, 1, 2, 3])
3513 assert_equal(x._mask, [1, 0, 0, 0])
3514
3515 x = [1, 4, 2, 3]
3516 sortedx = sort(x)
3517 assert_(not isinstance(sorted, MaskedArray))
3518
3519 x = array([0, 1, -1, -2, 2], mask=nomask, dtype=np.int8)
3520 sortedx = sort(x, endwith=False)
3521 assert_equal(sortedx._data, [-2, -1, 0, 1, 2])
3522 x = array([0, 1, -1, -2, 2], mask=[0, 1, 0, 0, 1], dtype=np.int8)
3523 sortedx = sort(x, endwith=False)
3524 assert_equal(sortedx._data, [1, 2, -2, -1, 0])
3525 assert_equal(sortedx._mask, [1, 1, 0, 0, 0])
3526
3527 x = array([0, -1], dtype=np.int8)
3528 sortedx = sort(x, kind="stable")
3529 assert_equal(sortedx, array([-1, 0], dtype=np.int8))
3530
3531 def test_stable_sort(self):
3532 x = array([1, 2, 3, 1, 2, 3], dtype=np.uint8)

Callers

nothing calls this directly

Calls 5

arrayFunction · 0.90
sortFunction · 0.90
assert_equalFunction · 0.90
sortMethod · 0.80
assert_Function · 0.50

Tested by

no test coverage detected