Exemplo n.º 1
0
def test_large_int():
    data = np.array([2 ** 60, 2 ** 60 + 1], dtype=np.uint64)
    r = rankdata(data)
    assert_array_equal(r, [1.0, 2.0])

    data = np.array([2 ** 60, 2 ** 60 + 1], dtype=np.int64)
    r = rankdata(data)
    assert_array_equal(r, [1.0, 2.0])

    data = np.array([2 ** 60, -(2 ** 60) + 1], dtype=np.int64)
    r = rankdata(data)
    assert_array_equal(r, [2.0, 1.0])
Exemplo n.º 2
0
def test_big_tie():
    for n in [10000, 100000, 1000000]:
        data = np.ones(n, dtype=int)
        r = rankdata(data)
        expected_rank = 0.5 * (n + 1)
        assert_array_equal(r, expected_rank * data,
                           "test failed with n=%d" % n)
Exemplo n.º 3
0
def test_basic():
    """Basic tests of rankdata."""
    data = [100, 10, 50]
    expected = np.array([3.0, 1.0, 2.0], dtype=np.float64)
    a = np.array(data, dtype=int)
    r = rankdata(a)
    assert_array_equal(r, expected)

    data = [40, 10, 30, 10, 50]
    expected = np.array([4.0, 1.5, 3.0, 1.5, 5.0], dtype=np.float64)
    a = np.array(data, dtype=int)
    r = rankdata(a)
    assert_array_equal(r, expected)

    data = [20, 20, 20, 10, 10, 10]
    expected = np.array([5.0, 5.0, 5.0, 2.0, 2.0, 2.0], dtype=np.float64)
    a = np.array(data, dtype=int)
    r = rankdata(a)
    assert_array_equal(r, expected)
    # The docstring states explicitly that the argument is flattened.
    a2d = a.reshape(2, 3)
    r = rankdata(a2d)
    assert_array_equal(r, expected)
Exemplo n.º 4
0
 def check_ranks(a):
     for method in "min", "max", "dense", "ordinal", "average":
         out = rankdata(a, method=method)
         assert_array_equal(out, rankf[method](a))
Exemplo n.º 5
0
def test_empty():
    """rankdata([]) should return an empty array."""
    a = np.array([], dtype=int)
    r = rankdata(a)
    assert_array_equal(r, np.array([], dtype=np.float64))
Exemplo n.º 6
0
def test_cases():
    for values, method, expected in _cases:
        r = rankdata(values, method=method)
        assert_array_equal(r, expected)
Exemplo n.º 7
0
def test_one():
    """Check rankdata with an array of length 1."""
    data = [100]
    a = np.array(data, dtype=int)
    r = rankdata(a)
    assert_array_equal(r, np.array([1.0], dtype=np.float64))