<commit_before>from blaze.api.dplyr import *

L = [[1, 'Alice',   100],
     [2, 'Bob',    -200],
     [3, 'Charlie', 300],
     [4, 'Dennis',  400],
     [5, 'Edith',  -500]]

t = TableSymbol('t', '{id: int, name: string, amount: int}')

inject(t)

def test_Filter():
    assert Filter(t, name=='Alice').isidentical(t[t.name=='Alice'])
    assert Filter(t, name=='Alice', amount>1).isidentical(
            t[(t.name=='Alice') & (t.amount > 1)])


def test_select():
    assert select(t, name, amount).isidentical(t[['name', 'amount']])


def test_mutate():
    expr = mutate(t, x = amount + id)
    assert expr.columns == ['id', 'name', 'amount', 'x']
#     assert expr.x.isidentical(t.amount + t.id)


def test_groupby():
    g = group_by(t, name)
    result = summarize(g, sum=amount.sum())
    assert isinstance(result.child, By)
    assert result.columns == ['name', 'sum']


def test_groupby_multicolumn():
    g = group_by(t, name, id)
    result = summarize(g, count=amount.count())
    assert isinstance(result.child, By)
    assert result.columns == ['name', 'id', 'count']<commit_msg>dplyr: summary now returns by, not relabel.  Edit tests<commit_after>from blaze.api.dplyr import *

L = [[1, 'Alice',   100],
     [2, 'Bob',    -200],
     [3, 'Charlie', 300],
     [4, 'Dennis',  400],
     [5, 'Edith',  -500]]

t = TableSymbol('t', '{id: int, name: string, amount: int}')

inject(t)

def test_Filter():
    assert Filter(t, name=='Alice').isidentical(t[t.name=='Alice'])
    assert Filter(t, name=='Alice', amount>1).isidentical(
            t[(t.name=='Alice') & (t.amount > 1)])


def test_select():
    assert select(t, name, amount).isidentical(t[['name', 'amount']])


def test_mutate():
    expr = mutate(t, x = amount + id)
    assert expr.columns == ['id', 'name', 'amount', 'x']
#     assert expr.x.isidentical(t.amount + t.id)


def test_groupby():
    g = group_by(t, name)
    result = summarize(g, sum=amount.sum())
    assert isinstance(result, By)
    assert result.columns == ['name', 'sum']


def test_groupby_multicolumn():
    g = group_by(t, name, id)
    result = summarize(g, count=amount.count())
    assert isinstance(result, By)
    assert result.columns == ['name', 'id', 'count']
{'fraction_non_alphanumeric': 0.20027002700270027, 'fraction_numerical': 0.019801980198019802, 'mean_word_length': 3.564681724845996, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2986688', 'n_tokens_mistral': 856, 'n_tokens_neox': 809, 'n_words': 197}