예제 #1
0
def test_dump(resource_tmp_file):
    # synonym of save
    p = Pipe() +\
        Segment(lambda x: x+1, "step1") + \
        Segment(lambda x: x+1, "step2")

    p._dump(resource_tmp_file)
예제 #2
0
def test_cache_basic():
    if sys.version_info > (3, 0, 0):
        p = Pipe(cached=True) +\
            (lambda x: x)

        assert p(2) == 2
        assert p(2) == 2
        assert p.__cache_info__()[1] == 1 # misses
        assert p.__cache_info__()[0] == 1 # hits
예제 #3
0
def test_save_fitted_load_predict(resource_tmp_file):
    p = Pipe() +\
        Segment(anova_filter, 'anova') +\
        Segment(clf, 'svc')

    p.fit(X, y)
    p._save(resource_tmp_file)
    p = Pipe._load(resource_tmp_file)
    p.predict(X)
예제 #4
0
def test_no_input():
    p = Pipe() +\
        Segment(lambda *_: 2)

    p2 = Pipe() + \
        Segment(lambda *_: 2) + \
        Segment(lambda x: x)

    assert p() == 2
    assert p(5) == 2

    assert p2() == 2
    assert p2(5) == 2
예제 #5
0
def test_multiple_args():
    def test_func(x, y):
        return (x, y)

    p = Pipe() +\
        test_func +\
        (lambda x, y: (x,y))

    assert p(1, 2) == (1, 2)

    p = Pipe() + \
        (lambda a, b, c, d: (a, b, c, d))

    assert p(1, 2, 3, 4) == (1, 2, 3, 4)
예제 #6
0
def test_kwargs2():
    p = Pipe() +\
        Segment(my_func, description="test", b=1) +\
        Segment(my_func, description="test", b=2)

    assert p(1) == 4
    assert p.bla(1) == 4


# def test_args():
#     p = Pipe() +\
#         Segment(my_func, description="test", 1)
#
#     assert p(1) == 2
예제 #7
0
def test_load_save_utility_funcs(resource_tmp_file):
    from mlpipe.utils import save, load
    p = Pipe() +\
        Segment(lambda x: x+1, "step1") + \
        Segment(lambda x: x+1, "step2")

    save(p, resource_tmp_file)
    load(resource_tmp_file)
예제 #8
0
def test_sklearn_pipe_fit_predict1():
    p = Pipe() +\
        Segment(anova_filter, 'anova') +\
        Segment(clf, 'svc')

    p.fit(X, y)
    p.predict(X)
예제 #9
0
def test_sklearn_pipe_serialize():
    def dummy(*args):
        return args

    p = Pipe() +\
        Segment(anova_filter, 'anova') +\
        Segment(dummy) +\
        Segment(clf, 'svc')

    p.fit(X, y)
    p.predict(X, y=None)
예제 #10
0
def test_nonsegment_lambda2_wo_attr():
    p = Pipe() +\
        (lambda x: x+2) + \
        (lambda x: x + 2)

    assert p(5) == 9
예제 #11
0
def test_error_non_callable():
    # non callable objects should raise exception
    with pytest.raises(TypeError) as e_info:
        p = Pipe() + 3
        p()
예제 #12
0
def test_lambda2_w_attr():
    p = Pipe() +\
        Segment(lambda x: x+2) + \
        Segment(lambda x: x + 2)

    assert p.testattr(5) == 9
예제 #13
0
def test_lambda1_wo_attr():
    p = Pipe() +\
        Segment(lambda x: x+2)

    assert p(5) == 7
예제 #14
0
def test_load_after_dump(resource_tmp_file):
    p = Pipe._load(resource_tmp_file)

    assert p(2) == 4
예제 #15
0
def test_kwargs():
    p = Pipe() + Segment(my_func, b=1)

    assert p(1) == 2
    assert p.bla(1) == 2
예제 #16
0
def test_save(resource_tmp_file):
    p = Pipe() +\
        Segment(lambda x: x+1, "step1") + \
        Segment(lambda x: x+1, "step2")

    p._save(resource_tmp_file)
예제 #17
0
def test_dumps():
    p = Pipe() +\
        Segment(lambda x: x+1, "step1") + \
        Segment(lambda x: x+1, "step2")

    p._dumps()