def test_traverse(): t = TableSymbol('t', '{name: string, amount: int}') assert t in list(t.traverse()) expr = t[t['amount'] < 0]['name'] trav = list(expr.traverse()) assert any(t['amount'].isidentical(x) for x in trav) assert any((t['amount'] < 0).isidentical(x) for x in trav)
def test_reductions(): assert compute(sum(t['amount']), data) == 100 + 200 + 50 assert compute(min(t['amount']), data) == 50 assert compute(max(t['amount']), data) == 200 assert compute(nunique(t['amount']), data) == 3 assert compute(nunique(t['name']), data) == 2 assert compute(count(t['amount']), data) == 3 assert compute(any(t['amount'] > 150), data) is True assert compute(any(t['amount'] > 250), data) is False
def test_reductions(): assert compute(mean(t['amount']), df) == 350./3 assert compute(count(t['amount']), df) == 3 assert compute(sum(t['amount']), df) == 100 + 200 + 50 assert compute(min(t['amount']), df) == 50 assert compute(max(t['amount']), df) == 200 assert compute(nunique(t['amount']), df) == 3 assert compute(nunique(t['name']), df) == 2 assert compute(any(t['amount'] > 150), df) == True assert compute(any(t['amount'] > 250), df) == False assert compute(var(t['amount']), df) == df.amount.var(ddof=0) assert compute(var(t['amount'], unbiased=True), df) == df.amount.var() assert compute(std(t['amount']), df) == df.amount.std(ddof=0) assert compute(std(t['amount'], unbiased=True), df) == df.amount.std()