Пример #1
0
def test_recursive_rowfunc():
    f = rrowfunc(t['name'], t)
    assert [f(row) for row in data] == [row[0] for row in data]

    f = rrowfunc(t['amount'] + t['id'], t)
    assert [f(row) for row in data] == [row[1] + row[2] for row in data]

    assert raises(Exception, lambda: rrowfunc(t[t['amount'] < 0]['name'], t))
Пример #2
0
def test_recursive_rowfunc():
    f = rrowfunc(t['name'], t)
    assert [f(row) for row in data] == [row[0] for row in data]

    f = rrowfunc(t['amount'] + t['id'], t)
    assert [f(row) for row in data] == [row[1] + row[2] for row in data]

    assert raises(Exception, lambda: rrowfunc(t[t['amount'] < 0]['name'], t))
def test_gzopen_json():
    with tmpfile('.json.gz') as filename:
        with gzip.open(filename, 'w') as f:
            f.write('[[1, 1], [2, 2]]')

        # Not a valid JSON file
        assert raises(Exception, lambda: list(JSON(filename, schema='2 * int')))

        dd = JSON(filename, schema='2 * int', open=gzip.open)

        assert list(dd) == [[1, 1], [2, 2]]
def test_gzopen_csv():
    with tmpfile('.csv.gz') as filename:
        with gzip.open(filename, 'w') as f:
            f.write('1,1\n2,2')

        # Not a valid CSV file
        assert raises(Exception, lambda: list(CSV(filename, schema='2 * int')))

        dd = CSV(filename, schema='2 * int', open=gzip.open)

        assert list(dd) == [[1, 1], [2, 2]]
Пример #5
0
def test_union():
    schema = '{x: int, y: int, z: int}'
    a = TableSymbol('a', schema)
    b = TableSymbol('b', schema)
    c = TableSymbol('c', schema)

    u = union(a, b, c)
    assert u.schema == a.schema

    assert raises(Exception,
                  lambda: union(a, TableSymbol('q', '{name: string}')))
def test_gzopen_csv():
    with tmpfile('.csv.gz') as filename:
        with gzip.open(filename, 'w') as f:
            f.write('1,1\n2,2')

        # Not a valid CSV file
        assert raises(Exception, lambda: list(CSV(filename, schema='2 * int')))

        dd = CSV(filename, schema='2 * int', open=gzip.open)

        assert list(dd) == [[1, 1], [2, 2]]
Пример #7
0
def test_union():
    schema = '{x: int, y: int, z: int}'
    a = TableSymbol('a', schema)
    b = TableSymbol('b', schema)
    c = TableSymbol('c', schema)

    u = union(a, b, c)
    assert u.schema == a.schema

    assert raises(Exception,
                  lambda: union(a, TableSymbol('q', '{name: string}')))
def test_gzopen_json():
    with tmpfile('.json.gz') as filename:
        with gzip.open(filename, 'w') as f:
            f.write('[[1, 1], [2, 2]]')

        # Not a valid JSON file
        assert raises(Exception,
                      lambda: list(JSON(filename, schema='2 * int')))

        dd = JSON(filename, schema='2 * int', open=gzip.open)

        assert list(dd) == [[1, 1], [2, 2]]
Пример #9
0
def test_gzopen_json():
    with tmpfile('.json.gz') as filename:
        f = gzip.open(filename, 'wt')
        f.write('[[1, 1], [2, 2]]')
        f.close()

        # Not a valid JSON file
        assert raises(Exception, lambda: list(JSON(filename, schema='2 * int')))

        dd = JSON(filename, schema='2 * int', open=gzip.open)

        assert tuplify(list(dd)) == ((1, 1), (2, 2))
    def test_table_creation(self):
        dd = SQL(self.engine,
                 'testtable',
                 schema='{name: string, amount: int}',
                 primary_key='name')
        assert self.engine.has_table('testtable')

        assert dd.table.columns.get('name').primary_key
        assert not dd.table.columns.get('amount').primary_key
        assert dd.dshape == dshape('var * {name: string, amount: int}')

        assert raises(ValueError, lambda: SQL(self.engine, 'testtable2'))
Пример #11
0
    def test_table_creation(self):
        dd = SQL(self.engine, 'testtable',
                              schema='{name: string, amount: int}',
                              primary_key='name')
        assert self.engine.has_table('testtable')


        assert dd.table.columns.get('name').primary_key
        assert not dd.table.columns.get('amount').primary_key
        assert dd.dshape == dshape('var * {name: string, amount: int}')

        assert raises(ValueError, lambda: SQL(self.engine, 'testtable2'))
Пример #12
0
def test_gzopen_json():
    with tmpfile('.json.gz') as filename:
        f = gzip.open(filename, 'wt')
        f.write('[[1, 1], [2, 2]]')
        f.close()

        # Not a valid JSON file
        assert raises(Exception,
                      lambda: list(JSON(filename, schema='2 * int')))

        dd = JSON(filename, schema='2 * int', open=gzip.open)

        assert tuplify(list(dd)) == ((1, 1), (2, 2))
Пример #13
0
def test_gzopen_csv():
    with tmpfile('.csv.gz') as filename:
        f = gzip.open(filename, 'wt')
        f.write('1,1\n2,2')
        f.close()


        # Not a valid CSV file
        assert raises(Exception, lambda: list(CSV(filename, schema='2 * int')))

        dd = CSV(filename, schema='2 * int', open=partial(gzip.open, mode='rt'))

        assert tuplify(list(dd)) == ((1, 1), (2, 2))
Пример #14
0
def test_selection_typecheck():
    t = symbol('t', 'var * {name: string, amount: int, id: int}')

    assert raises(TypeError, lambda: t[t['amount'] + t['id']])
    assert raises(TypeError, lambda: t[t['name']])
Пример #15
0
def test_raise_error_if_join_on_no_columns():
    a = symbol('a', 'var * {x: int}')
    b = symbol('b', 'var * {y: int}')

    assert raises(ValueError, lambda: join(a, b))
Пример #16
0
def test_multiple_renames_on_series_fails():
    t = symbol('s', 'var * {timestamp: datetime}')
    ts = t.timestamp
    assert raises(ValueError, lambda: ts.relabel({'timestamp': 'date',
                                                  'hello': 'world'}))
Пример #17
0
def test_map_with_rename():
    t = symbol('s', 'var * {timestamp: datetime}')
    result = t.timestamp.map(lambda x: x.date(), schema='{date: datetime}')
    assert raises(ValueError, lambda: result.relabel({'timestamp': 'date'}))
    assert result.fields == ['date']
Пример #18
0
from blaze import CSV, JSON
import subprocess
import tempfile
import json
import os
from blaze.utils import filetext, tmpfile, raises
from blaze.compatibility import PY3

from datashape import discover, dshape

from blaze import drop, into, create_index
from blaze.utils import assert_allclose


no_mongoimport = pytest.mark.skipif(raises(OSError,
    lambda : subprocess.Popen('mongoimport',
                              shell=os.name != 'nt',
                              stdout=subprocess.PIPE).wait()),
    reason='mongoimport cannot be found')


@pytest.yield_fixture(scope='module')
def conn():
    pymongo = pytest.importorskip('pymongo')
    try:
        c = pymongo.MongoClient()
    except pymongo.errors.ConnectionFailure:
        pytest.skip('No mongo server running')
    else:
        yield c
        c.close()
Пример #19
0
def test_shapes_raise_errors():
    assert raises(ValueError, lambda: w + x)
Пример #20
0
def test_improper_selection():
    t = TableSymbol('t', '{x: int, y: int, z: int}')

    assert raises(Exception, lambda: t[t['x'] > 0][t.sort()[t['y' > 0]]])
Пример #21
0
def test_raise_error_if_join_on_no_columns():
    a = symbol('a', 'var * {x: int}')
    b = symbol('b', 'var * {y: int}')

    assert raises(ValueError, lambda: join(a, b))
Пример #22
0
def test_improper_selection():
    t = symbol('t', 'var * {x: int, y: int, z: int}')

    assert raises(Exception, lambda: t[t['x'] > 0][t.sort()[t['y' > 0]]])
Пример #23
0
from blaze.data import CSV, JSON
import subprocess
import tempfile
import json
import os
from blaze.utils import filetext, tmpfile, raises
from blaze.compatibility import PY3, PY2

from datashape import discover, dshape

from blaze import drop, into, create_index
from blaze.utils import assert_allclose
from blaze.resource import resource

no_mongoimport = pytest.mark.skipif(raises(
    OSError, lambda: subprocess.Popen(
        'mongoimport', shell=os.name != 'nt', stdout=subprocess.PIPE).wait()),
                                    reason='mongoimport cannot be found')


@pytest.yield_fixture(scope='module')
def conn():
    pymongo = pytest.importorskip('pymongo')
    try:
        c = pymongo.MongoClient()
    except pymongo.errors.ConnectionFailure:
        pytest.skip('No mongo server running')
    else:
        yield c
        c.close()
Пример #24
0
def test_iter_raises_not_implemented_Error():
    e = Symbol('e', '5 * {x: int, "a b": int}')
    assert raises(NotImplementedError, lambda: iter(e))
Пример #25
0
def test_shapes_raise_errors():
    assert raises(ValueError, lambda: w + x)
Пример #26
0
def test_dir():
    i = symbol('i', '10 * int')
    d = symbol('d', '10 * datetime')

    assert i + 1
    assert raises(Exception, lambda: d + 1)
Пример #27
0
def test_improper_selection():
    t = TableSymbol("t", "{x: int, y: int, z: int}")

    assert raises(Exception, lambda: t[t["x"] > 0][t.sort()[t["y" > 0]]])
Пример #28
0
from blaze.utils import raises
from odo import URL, CSV

import pandas as pd
import pandas.util.testing as tm

from functools import partial

try:
    from urllib2 import urlopen
    from urllib2 import HTTPError, URLError
except ImportError:
    from urllib.request import urlopen
    from urllib.error import HTTPError, URLError

pytestmark = pytest.mark.skipif(raises(URLError,
                                       partial(urlopen, "http://google.com")),
                                reason='unable to connect to google.com')

iris_url = ('https://raw.githubusercontent.com/'
            'blaze/blaze/master/blaze/examples/data/iris.csv')

@pytest.fixture
def iris_local():
    thisdir = os.path.abspath(os.path.dirname(__file__))
    return data(os.path.join(thisdir, os.pardir, os.pardir, "examples", "data", "iris.csv"))

def test_url_csv_data(iris_local):
    iris_remote = data(iris_url)
    assert isinstance(iris_remote.data, URL(CSV))
    iris_remote_df = compute(iris_remote)
    assert isinstance(iris_remote_df, pd.DataFrame)
Пример #29
0
def test_selection_typecheck():
    t = TableSymbol('t', '{name: string, amount: int, id: int}')

    assert raises(TypeError, lambda: t[t['amount'] + t['id']])
    assert raises(TypeError, lambda: t[t['name']])
Пример #30
0
from blaze.utils import raises
from odo import URL, CSV

import pandas as pd
import pandas.util.testing as tm

from functools import partial

try:
    from urllib2 import urlopen
    from urllib2 import HTTPError, URLError
except ImportError:
    from urllib.request import urlopen
    from urllib.error import HTTPError, URLError

pytestmark = pytest.mark.skipif(raises(URLError,
                                       partial(urlopen, "http://google.com")),
                                reason='unable to connect to google.com')

iris_url = ('https://raw.githubusercontent.com/'
            'blaze/blaze/master/blaze/examples/data/iris.csv')


@pytest.fixture
def iris_local():
    thisdir = os.path.abspath(os.path.dirname(__file__))
    return Data(
        os.path.join(thisdir, os.pardir, os.pardir, "examples", "data",
                     "iris.csv"))


def test_url_csv_data(iris_local):
Пример #31
0
def test_selection_typecheck():
    t = TableSymbol("t", "{name: string, amount: int, id: int}")

    assert raises(TypeError, lambda: t[t["amount"] + t["id"]])
    assert raises(TypeError, lambda: t[t["name"]])
Пример #32
0
def test_iter_raises_not_implemented_Error():
    e = symbol('e', '5 * {x: int, "a b": int}')
    assert raises(NotImplementedError, lambda: iter(e))