Exemplo n.º 1
0
def test_table_resource():
    with tmpfile('csv') as filename:
        ds = dshape('var * {a: int, b: int}')
        csv = CSV(filename)
        append(csv, [[1, 2], [10, 20]], dshape=ds)

        t = Data(filename)
        assert isinstance(t.data, CSV)
        assert into(list, compute(t)) == into(list, csv)
Exemplo n.º 2
0
def test_incompatible_types():
    d = Data(pd.DataFrame(L, columns=["id", "name", "amount"]))

    with pytest.raises(ValueError):
        d.id == "foo"

    result = compute(d.id == 3)
    expected = pd.Series([False, False, True, False, False], name="id")
    tm.assert_series_equal(result, expected)
Exemplo n.º 3
0
def test_incompatible_types():
    d = Data(pd.DataFrame(L, columns=['id', 'name', 'amount']))

    with pytest.raises(ValueError):
        d.id == 'foo'

    result = compute(d.id == 3)
    expected = pd.Series([False, False, True, False, False], name='id')
    tm.assert_series_equal(result, expected)
Exemplo n.º 4
0
def test_Data_on_json_is_concrete():
    d = Data(example('accounts-streaming.json'))

    assert compute(d.amount.sum()) == 100 - 200 + 300 + 400 - 500
    assert compute(d.amount.sum()) == 100 - 200 + 300 + 400 - 500
Exemplo n.º 5
0
def test_into_nd_array_column_failure():
    tble = Data(L, fields=['id', 'name', 'balance'])
    expr = tble[tble['balance'] < 0]
    colarray = into(np.ndarray, expr)
    assert len(list(compute(expr))) == len(colarray)
Exemplo n.º 6
0
def test_into_nd_array_selection():
    t = Data(L, fields=['id', 'name', 'balance'])
    expr = t[t['balance'] < 0]
    selarray = into(np.ndarray, expr)
    assert len(list(compute(expr))) == len(selarray)
Exemplo n.º 7
0
def test_into_np_ndarray_column():
    t = Data(L, fields=['id', 'name', 'balance'])
    expr = t[t.balance < 0].name
    colarray = into(np.ndarray, expr)
    assert len(list(compute(expr))) == len(colarray)
Exemplo n.º 8
0
def test_into_nd_array_column_failure():
    tble = Data(L, fields=["id", "name", "balance"])
    expr = tble[tble["balance"] < 0]
    colarray = into(np.ndarray, expr)
    assert len(list(compute(expr))) == len(colarray)
Exemplo n.º 9
0
def test_compute_on_Data_gives_back_data():
    assert compute(Data([1, 2, 3])) == [1, 2, 3]
Exemplo n.º 10
0
def test_into_np_ndarray_column():
    t = Data(L, fields=['id', 'name', 'balance'])
    expr = t[t.balance < 0].name
    colarray = into(np.ndarray, expr)
    assert len(list(compute(expr))) == len(colarray)
Exemplo n.º 11
0
def test_compute():
    assert list(compute(t['amount'] + 1)) == [101, 201]
Exemplo n.º 12
0
def test_compute_on_Data_gives_back_data():
    assert compute(Data([1, 2, 3])) == [1, 2, 3]
Exemplo n.º 13
0
def test_resources_fail():
    t = symbol('t', 'var * {x: int, y: int}')
    d = t[t['x'] > 100]
    with pytest.raises(ValueError):
        compute(d)
Exemplo n.º 14
0
def test_Data_on_json_is_concrete():
    d = Data(example('accounts-streaming.json'))

    assert compute(d.amount.sum()) == 100 - 200 + 300 + 400 - 500
    assert compute(d.amount.sum()) == 100 - 200 + 300 + 400 - 500
Exemplo n.º 15
0
def test_resources_fail():
    t = symbol("t", "var * {x: int, y: int}")
    d = t[t["x"] > 100]
    with pytest.raises(ValueError):
        compute(d)
Exemplo n.º 16
0
def test_into_nd_array_selection():
    t = Data(L, fields=['id', 'name', 'balance'])
    expr = t[t['balance'] < 0]
    selarray = into(np.ndarray, expr)
    assert len(list(compute(expr))) == len(selarray)
Exemplo n.º 17
0
def test_resources_fail():
    t = symbol('t', 'var * {x: int, y: int}')
    d = t[t['x'] > 100]
    with pytest.raises(ValueError):
        compute(d)
Exemplo n.º 18
0
def test_into_nd_array_column_failure():
    tble = Data(L, fields=['id', 'name', 'balance'])
    expr = tble[tble['balance'] < 0]
    colarray = into(np.ndarray, expr)
    assert len(list(compute(expr))) == len(colarray)
Exemplo n.º 19
0
def test_compute():
    assert list(compute(t['amount'] + 1)) == [101, 201]
Exemplo n.º 20
0
def test_into_nd_array_selection():
    t = Data(L, fields=["id", "name", "balance"])
    expr = t[t["balance"] < 0]
    selarray = into(np.ndarray, expr)
    assert len(list(compute(expr))) == len(selarray)