Example #1
0
def test_corners():
    # fails for length differences
    assert_raises(ValueError, approx, x=[1, 2, 3], y=[1, 2], xout=1.0)

    # fails for bad string
    assert_raises(ValueError,
                  approx,
                  x=table,
                  y=table,
                  xout=1.0,
                  method='bad-string')

    # fails for bad length
    assert_raises(ValueError, approx, x=[], y=[], xout=[], ties='mean')

    # fails for bad length
    assert_raises(ValueError, approx, x=[], y=[], xout=[], method='constant')

    # fails for linear when < 2 samples
    assert_raises(ValueError,
                  approx,
                  x=[1],
                  y=[1],
                  xout=[],
                  method='linear',
                  ties='ordered')

    # but *doesn't* fail for constant when < 2 samples
    approx(x=[1], y=[1], xout=[], method='constant', ties='ordered')

    # fails for bad length
    assert_raises(ValueError, approx, x=[], y=[], xout=[], method='constant')
Example #2
0
def test_approx_precision():
    # Test an example from R vs. Python to compare the expected values and
    # make sure we get as close as possible. This is from an ADFTest where k=1
    # and x=austres
    tableipl = np.array([[-4.0664], [-3.7468], [-3.462], [-3.1572], [-1.2128],
                         [-0.8928], [-0.6104], [-0.2704]])

    _, interpol = approx(tableipl, ADFTest.tablep, xout=-1.337233, rule=2)
    assert np.allclose(interpol, 0.84880354)  # in R we get 0.8488036
Example #3
0
def test_approx_rule2():
    # for rule = 2
    x, y = approx(table, tablep, stat, rule=2)
    assert_array_almost_equal(x, c(1.01))
    assert_array_almost_equal(y, c(0.01))
Example #4
0
def test_approx_rule1():
    # for rule = 1
    x, y = approx(table, tablep, stat, rule=1)
    assert_array_almost_equal(x, c(1.01))
    assert_array_almost_equal(y, c(np.nan))
Example #5
0
def test_valid_corner():
    # *doesn't* fail for constant when < 2 samples
    approx(x=[1], y=[1], xout=[], method='constant', ties='ordered')
Example #6
0
def test_corner_errors(kwargs):
    with pytest.raises(ValueError):
        approx(**kwargs)