Example #1
0
def test_dataframe_backed_repr_complex():
    df = pd.DataFrame([(1, 'Alice', 100), (2, 'Bob', -200),
                       (3, 'Charlie', 300), (4, 'Denis', 400),
                       (5, 'Edith', -500)],
                      columns=['id', 'name', 'balance'])
    t = Data(df)
    repr(t[t['balance'] < 0])
Example #2
0
def test_table_resource():
    with tmpfile('csv') as filename:
        csv = CSV(filename, 'w', schema='{x: int, y: int}')
        csv.extend([[1, 2], [10, 20]])

        t = Data(filename)
        assert isinstance(t.data, CSV)
        assert list(compute(t)) == list(csv)
Example #3
0
def test_repr():
    result = expr_repr(t['name'])
    print(result)
    assert isinstance(result, str)
    assert 'Alice' in result
    assert 'Bob' in result
    assert '...' not in result

    result = expr_repr(t['amount'] + 1)
    print(result)
    assert '101' in result

    t2 = Data(tuple((i, i**2) for i in range(100)), fields=['x', 'y'])
    result = expr_repr(t2)
    print(result)
    assert len(result.split('\n')) < 20
    assert '...' in result
Example #4
0
def test_create_with_schema():
    t = Data(data, schema='{name: string, amount: float32}')
    assert t.schema == dshape('{name: string, amount: float32}')
Example #5
0
def test_compute_on_Data_gives_back_data():
    assert compute(Data([1, 2, 3])) == [1, 2, 3]
Example #6
0
def test_table_raises_on_inconsistent_inputs():
    with pytest.raises(ValueError):
        t = Data(data,
                 schema='{name: string, amount: float32}',
                 dshape=dshape("{ name : string, amount : float32 }"))
Example #7
0
def test_data_passes_kwargs_to_resource():
    assert Data(example('iris.csv'), encoding='ascii').data.encoding == 'ascii'
Example #8
0
def test_can_trivially_create_pytables():
    Data(example('accounts.h5') + '::/accounts')
Example #9
0
def test_mutable_backed_repr():
    mutable_backed_table = Data([[0]], fields=['col1'])
    repr(mutable_backed_table)
Example #10
0
def test_can_trivially_create_csv_Data():
    Data(example('iris.csv'))
Example #11
0
def test_Data_attribute_repr():
    path = os.path.join(os.path.dirname(__file__), 'accounts.csv')
    t = Data(CSV(path))
    result = t.timestamp.day
    expected = pd.DataFrame({'timestamp_day': [25] * 3})
    assert repr(result) == repr(expected)
Example #12
0
def test_into_nd_array_column_failure():
    tble = Data(L, fields=['id', 'name', 'balance'])
    expr = tble[tble['balance'] < 0]
    colarray = into(nd.array, expr)
    assert len(list(compute(expr))) == len(colarray)
Example #13
0
def test_into_nd_array_selection():
    t = Data(L, fields=['id', 'name', 'balance'])
    expr = t[t['balance'] < 0]
    selarray = into(nd.array, expr)
    assert len(list(compute(expr))) == len(selarray)
Example #14
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)
Example #15
0
def test_create_with_raw_data():
    t = Data(data, columns=['name', 'amount'])
    assert t.schema == dshape('{name: string, amount: int64}')
    assert t.name
    assert t.data == data
Example #16
0
def test_can_trivially_create_csv_Data_with_unicode():
    if sys.version[0] == '2':
        assert isinstance(Data(example(u'iris.csv')).data, CSV)
Example #17
0
def test_can_trivially_create_sqlite_table():
    Data('sqlite:///' + example('iris.db') + '::iris')
Example #18
0
def test_dataframe_backed_repr():
    df = pd.DataFrame(data=[0], columns=['col1'])
    dataframe_backed_table = Data(df)
    repr(dataframe_backed_table)
Example #19
0
from blaze.expr.table import Symbol
from datashape import dshape
from blaze.utils import tmpfile, example
import pytest
import sys

import pandas as pd
import numpy as np
from dynd import nd

data = (('Alice', 100), ('Bob', 200))

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

t = Data(data, columns=['name', 'amount'])


def test_table_raises_on_inconsistent_inputs():
    with pytest.raises(ValueError):
        t = Data(data,
                 schema='{name: string, amount: float32}',
                 dshape=dshape("{ name : string, amount : float32 }"))


def test_resources():
    assert t._resources() == {t: t.data}


def test_resources_fail():
    t = Symbol('t', 'var * {x: int, y: int}')