示例#1
0
def test_multiple_object_ids():
    data = [{
        'x': 1,
        'y': 2,
        'other': ObjectId('1' * 24)
    }, {
        'x': 3,
        'y': 4,
        'other': ObjectId('2' * 24)
    }]
    with coll(data) as c:
        assert discover(c) == dshape('2 * {x: int64, y: int64}')

        assert convert(list, c) == [(1, 2), (3, 4)]
示例#2
0
def test_discover_csv_yields_string_on_totally_empty_columns():
    expected = dshape('var * {a: int64, b: ?string, c: int64}')
    with filetext('a,b,c\n1,,3\n4,,6\n7,,9') as fn:
        csv = CSV(fn, has_header=True)
        assert discover(csv) == expected
示例#3
0
文件: test_sas.py 项目: mrocklin/into
from into.backends.sas import discover, sas_to_iterator
from into.utils import tmpfile
from into import append, convert, resource, dshape


cur_path = os.path.abspath(os.path.dirname(__file__))
test_path = os.path.join(cur_path, 'airline.sas7bdat')
sasfile = SAS7BDAT(test_path)


columns = ("DATE", "AIR", "mon1", "mon2", "mon3", "mon4", "mon5", "mon6",
           "mon7", "mon8", "mon9", "mon10", "mon11", "mon12", "t", "Lair")

ds = dshape('''var * {DATE: date, AIR: float64, mon1: float64, mon2: float64,
                      mon3: float64, mon4: float64, mon5: float64,
                      mon6: float64, mon7: float64, mon8: float64,
                      mon9: float64, mon10: float64, mon11: float64,
                      mon12: float64, t: float64, Lair: float64}''')


def test_resource_sas7bdat():
    assert isinstance(resource(test_path), SAS7BDAT)


def test_discover_sas():
    assert discover(sasfile) == ds


def test_convert_sas_to_dataframe():
    df = convert(pd.DataFrame, sasfile)
    assert isinstance(df, pd.DataFrame)
示例#4
0
from sas7bdat import SAS7BDAT

from into.backends.sas import discover, sas_to_iterator
from into.utils import tmpfile
from into import append, convert, resource, dshape

cur_path = os.path.abspath(os.path.dirname(__file__))
test_path = os.path.join(cur_path, 'airline.sas7bdat')
sasfile = SAS7BDAT(test_path)

columns = ("DATE", "AIR", "mon1", "mon2", "mon3", "mon4", "mon5", "mon6",
           "mon7", "mon8", "mon9", "mon10", "mon11", "mon12", "t", "Lair")

ds = dshape('''var * {DATE: date, AIR: float64, mon1: float64, mon2: float64,
                      mon3: float64, mon4: float64, mon5: float64,
                      mon6: float64, mon7: float64, mon8: float64,
                      mon9: float64, mon10: float64, mon11: float64,
                      mon12: float64, t: float64, Lair: float64}''')


def test_resource_sas7bdat():
    assert isinstance(resource(test_path), SAS7BDAT)


def test_discover_sas():
    assert discover(sasfile) == ds


def test_convert_sas_to_dataframe():
    df = convert(pd.DataFrame, sasfile)
    assert isinstance(df, pd.DataFrame)
示例#5
0
    'amount': 100
}, {
    'name': 'Alice',
    'amount': 200
}, {
    'name': 'Bob',
    'amount': 100
}, {
    'name': 'Bob',
    'amount': 200
}, {
    'name': 'Bob',
    'amount': 300
})

ds = dshape('var * {name: string, amount: int}')


def test_discover():
    with coll(bank) as c:
        assert discover(bank) == discover(c)


def test_append_convert():
    with coll([]) as c:
        append(c, bank, dshape=ds)

        assert convert(list, c,
                       dshape=ds) == list(pluck(['name', 'amount'], bank))

示例#6
0
文件: test_csv.py 项目: jreback/into
def test_discover_csv_yields_string_on_totally_empty_columns():
    expected = dshape('var * {a: int64, b: string, c: int64}')
    with filetext('a,b,c\n1,,3\n4,,6\n7,,9') as fn:
        csv = CSV(fn, has_header=True)
        assert discover(csv) == expected