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)
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)
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)
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
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)
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)
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)
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)
def test_compute_on_Data_gives_back_data(): assert compute(Data([1, 2, 3])) == [1, 2, 3]
def test_compute(): assert list(compute(t['amount'] + 1)) == [101, 201]
def test_resources_fail(): t = symbol('t', 'var * {x: int, y: int}') d = t[t['x'] > 100] with pytest.raises(ValueError): compute(d)
def test_resources_fail(): t = symbol("t", "var * {x: int, y: int}") d = t[t["x"] > 100] with pytest.raises(ValueError): compute(d)
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)