Exemplo n.º 1
0
def test_median_array_input(window_size=71, length=1000):
    pipe = rq.Pipeline(rq.LowPass(window=window_size,
                                  portion=window_size // 2))
    x = example_input(length)
    y = pipe.feed(x)
    z = pd.Series(x).rolling(window_size).median()
    assert np.equal(y[window_size:], z.values[window_size:]).all(
    )  # exact equality, since no arithmetic is done on the numbers
Exemplo n.º 2
0
def test_median_scalar_inputs(window_size=3,
                              length=100):  # no interpolation yet
    pipe = rq.Pipeline(rq.LowPass(window=window_size,
                                  portion=window_size // 2))
    v = example_input(length)
    for i, x in enumerate(v):
        y = pipe.feed(x)
        if i >= window_size:
            assert y == np.median(v[(i - window_size + 1):(i + 1)])
Exemplo n.º 3
0
def test_basic_nans(window_size=5, length=20):
    # make sure the pipeline effectively flushes its contents with NaNs
    pipe = rq.Pipeline(rq.LowPass(window=window_size,
                                  portion=window_size // 2))
    x = example_input(length)
    y = pipe.feed(x)
    for i in range(window_size):
        pipe.feed(np.nan)
    z = pipe.feed(x)
    assert np.equal(y, z).all()
def test_fancy_interpolation(
    window_size=10,
    n_trials=200
):  # small windows may be more prone to boundary/edge-condition bugs
    for trial in range(n_trials):
        x = example_input(window_size)
        quantile = np.random.uniform()
        alpha, beta = np.random.uniform(size=2)
        pipe = rq.Pipeline(
            rq.LowPass(window=window_size,
                       quantile=quantile,
                       alpha=alpha,
                       beta=beta))
        y = pipe.feed(x)
        z = mquantiles(x, quantile, alphap=alpha, betap=beta)
        assert z == y[-1]
def test_innocuous_interpolation(window_size=1001, length=10000):
    pipe = rq.Pipeline(rq.LowPass(window=window_size, quantile=0.5))
    x = example_input(length)
    y = pipe.feed(x)
    z = pd.Series(x).rolling(window_size).median()
    assert np.equal(y[window_size:], z.values[window_size:]).all()
def test_typical_interpolation(window_size=40, quantile=0.2):
    x = example_input(window_size)  # one window only, due to scipy
    pipe = rq.Pipeline(rq.LowPass(window=window_size, quantile=quantile))
    y = pipe.feed(x)
    z = mquantiles(x, quantile, alphap=1, betap=1)
    assert z == y[-1]