Пример #1
0
def test_resample_deprecation(rng):
    data = [1, 2, 3]
    from numpy import VisibleDeprecationWarning

    with pytest.warns(VisibleDeprecationWarning):
        r = list(resample(data, 10))
        assert np.shape(r) == (10, 3)

    with pytest.warns(VisibleDeprecationWarning):
        resample(data, 10, "balanced")

    with pytest.warns(VisibleDeprecationWarning):
        with pytest.raises(ValueError):
            resample(data, 10, "foo")

    with pytest.warns(VisibleDeprecationWarning):
        resample(data, 10, "balanced", [1, 1, 2])

    with pytest.warns(VisibleDeprecationWarning):
        with pytest.raises(ValueError):
            resample(data, 10, "balanced", [1, 1])

    with pytest.warns(VisibleDeprecationWarning):
        resample(data, 10, "balanced", [1, 1, 2], rng)

    with pytest.warns(VisibleDeprecationWarning):
        resample(data, 10, "balanced", [1, 1, 2], 1)

    with pytest.warns(VisibleDeprecationWarning):
        with pytest.raises(TypeError):
            resample(data, 10, "balanced", [1, 1, 2], 1.3)

    with pytest.warns(VisibleDeprecationWarning):
        with pytest.raises(ValueError):  # too many arguments
            resample(data, 10, "balanced", [1, 1, 2], 1, 2)
Пример #2
0
def test_resample_full_strata(method):
    data = np.arange(3)
    for b in resample(data, size=2, strata=data, method=method):
        assert_equal(data, b)
Пример #3
0
def test_resample_invalid_strata_raises():
    msg = "must have the same shape"
    with pytest.raises(ValueError, match=msg):
        next(resample((1, 2, 3), strata=np.arange(4)))
Пример #4
0
def test_resample_equal_along_axis():
    data = np.reshape(np.tile([0, 1, 2], 3), newshape=(3, 3))
    for b in resample(data, size=2):
        assert_equal(data, b)
Пример #5
0
def test_resample_3d_parametric_normal_raises():
    with pytest.raises(ValueError):
        next(resample(np.ones((2, 2, 2)), method="normal"))
Пример #6
0
def test_resample_2d_parametric_raises(method):
    with pytest.raises(ValueError):
        next(resample(np.ones((2, 2)), method=method))
Пример #7
0
def test_resample_invalid_family_raises():
    msg = "Invalid family"
    with pytest.raises(ValueError, match=msg):
        next(resample((1, 2, 3), method="foobar"))
Пример #8
0
def run_resample(n, method):
    x = np.arange(n)
    r = []
    for b in resample(x, method=method):
        r.append(b)
    return r