Ejemplo n.º 1
0
def test_pre_compute():
    s = symbol('s', 'var * {a: int, b: int}')
    assert pre_compute(s, [(1, 2)]) == [(1, 2)]
    assert list(pre_compute(s, iter([(1, 2)]))) == [(1, 2)]
    assert list(pre_compute(s, iter([(1, 2), (3, 4)]))) == [(1, 2), (3, 4)]
    assert list(pre_compute(s, iter([{'a': 1, 'b': 2},
                                     {'a': 3, 'b': 4}]))) == [(1, 2), (3, 4)]
Ejemplo n.º 2
0
def test_pre_compute():
    s = symbol('s', 'var * {a: int, b: int}')
    assert pre_compute(s, [(1, 2)]) == [(1, 2)]
    assert list(pre_compute(s, iter([(1, 2)]))) == [(1, 2)]
    assert list(pre_compute(s, iter([(1, 2), (3, 4)]))) == [(1, 2), (3, 4)]
    assert list(pre_compute(s, iter([{'a': 1, 'b': 2},
                                     {'a': 3, 'b': 4}]))) == [(1, 2), (3, 4)]
Ejemplo n.º 3
0
def test_dicts():
    t = symbol('t', 'var * {name: string, amount: int, id: int}')

    L = [['Alice', 100, 1], ['Bob', 200, 2], ['Alice', 50, 3]]

    d = [{
        'name': 'Alice',
        'amount': 100,
        'id': 1
    }, {
        'name': 'Bob',
        'amount': 200,
        'id': 2
    }, {
        'name': 'Alice',
        'amount': 50,
        'id': 3
    }]

    assert list(pre_compute(t, d)) == list(map(tuple, L))

    for expr in [t.amount, t.amount.sum(), by(t.name, sum=t.amount.sum())]:
        assert eq(compute(expr, {t: L}), compute(expr, {t: d}))

    for expr in [t.amount, t.amount.sum(), by(t.name, sum=t.amount.sum())]:
        assert eq(compute(expr, {t: iter(L)}), compute(expr, {t: iter(d)}))
        assert eq(compute(expr, {t: iter(L)}), compute(expr, {t: L}))
Ejemplo n.º 4
0
def dont_test_pre_compute():
    b = bcolz.ctable(np.array([(1, 1., 10.), (2, 2., 20.), (3, 3., 30.)],
                              dtype=[('a', 'i8'), ('b', 'f8'), ('c', 'f8')]))

    s = symbol('s', discover(b))

    result = pre_compute(s[['a', 'b']], b)
    assert result.names == ['a', 'b']
Ejemplo n.º 5
0
def dont_test_pre_compute():
    b = bcolz.ctable(
        np.array([(1, 1., 10.), (2, 2., 20.), (3, 3., 30.)],
                 dtype=[('a', 'i8'), ('b', 'f8'), ('c', 'f8')]))

    s = symbol('s', discover(b))

    result = pre_compute(s[['a', 'b']], b)
    assert result.names == ['a', 'b']
Ejemplo n.º 6
0
def test_dicts():
    t = symbol('t', 'var * {name: string, amount: int, id: int}')

    L = [['Alice', 100, 1],
         ['Bob', 200, 2],
         ['Alice', 50, 3]]

    d = [{'name': 'Alice', 'amount': 100, 'id': 1},
         {'name': 'Bob', 'amount': 200, 'id': 2},
         {'name': 'Alice', 'amount': 50, 'id': 3}]

    assert list(pre_compute(t, d)) == list(map(tuple, L))

    for expr in [t.amount, t.amount.sum(), by(t.name, sum=t.amount.sum())]:
        assert eq(compute(expr, {t: L}),
                  compute(expr, {t: d}))

    for expr in [t.amount, t.amount.sum(), by(t.name, sum=t.amount.sum())]:
        assert eq(compute(expr, {t: iter(L)}),
                  compute(expr, {t: iter(d)}))
        assert eq(compute(expr, {t: iter(L)}),
                  compute(expr, {t: L}))