MCPcopy
hub / github.com/numpy/numpy / test_sort

Method test_sort

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

Source from the content-addressed store, hash-verified

3706 assert_equal(x._mask.shape, (4,))
3707
3708 def test_sort(self):
3709 # Test sort
3710 x = array([1, 4, 2, 3], mask=[0, 1, 0, 0], dtype=np.uint8)
3711
3712 sortedx = sort(x)
3713 assert_equal(sortedx._data, [1, 2, 3, 4])
3714 assert_equal(sortedx._mask, [0, 0, 0, 1])
3715
3716 sortedx = sort(x, endwith=False)
3717 assert_equal(sortedx._data, [4, 1, 2, 3])
3718 assert_equal(sortedx._mask, [1, 0, 0, 0])
3719
3720 x.sort()
3721 assert_equal(x._data, [1, 2, 3, 4])
3722 assert_equal(x._mask, [0, 0, 0, 1])
3723
3724 x = array([1, 4, 2, 3], mask=[0, 1, 0, 0], dtype=np.uint8)
3725 x.sort(endwith=False)
3726 assert_equal(x._data, [4, 1, 2, 3])
3727 assert_equal(x._mask, [1, 0, 0, 0])
3728
3729 x = [1, 4, 2, 3]
3730 sortedx = sort(x)
3731 assert_(not isinstance(sorted, MaskedArray))
3732
3733 x = array([0, 1, -1, -2, 2], mask=nomask, dtype=np.int8)
3734 sortedx = sort(x, endwith=False)
3735 assert_equal(sortedx._data, [-2, -1, 0, 1, 2])
3736 x = array([0, 1, -1, -2, 2], mask=[0, 1, 0, 0, 1], dtype=np.int8)
3737 sortedx = sort(x, endwith=False)
3738 assert_equal(sortedx._data, [1, 2, -2, -1, 0])
3739 assert_equal(sortedx._mask, [1, 1, 0, 0, 0])
3740
3741 x = array([0, -1], dtype=np.int8)
3742 sortedx = sort(x, kind="stable")
3743 assert_equal(sortedx, array([-1, 0], dtype=np.int8))
3744
3745 def test_stable_sort(self):
3746 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
assert_Function · 0.85
sortMethod · 0.45

Tested by

no test coverage detected