コード例 #1
0
def hive_table(host):
    name = ('temp' + str(uuid.uuid1()).replace('-', ''))[:30]
    uri = 'hive://hdfs@%s:10000/default::%s' % (host, name)

    try:
        yield uri
    finally:
        with ignoring(Exception):
            drop(uri)
コード例 #2
0
ファイル: test_hdfs.py プロジェクト: pskyp/shareapplication
def hive_table(host):
    name = ('temp' + str(uuid.uuid1()).replace('-', ''))[:30]
    uri = 'hive://hdfs@%s:10000/default::%s' % (host, name)

    try:
        yield uri
    finally:
        with ignoring(Exception):
            drop(uri)
コード例 #3
0
ファイル: test_json.py プロジェクト: MoherX/odo
def test_multiple_jsonlines():
    a, b = '_test_a1.json', '_test_a2.json'
    try:
        with ignoring(OSError):
            os.remove(a)
        with ignoring(OSError):
            os.remove(b)
        with open(a, 'w') as f:
            json.dump(dat, f)
        with open(b'_test_a2.json', 'w') as f:
            json.dump(dat, f)
        r = resource('_test_a*.json')
        result = convert(list, r)
        assert len(result) == len(dat) * 2
    finally:
        with ignoring(OSError):
            os.remove(a)
        with ignoring(OSError):
            os.remove(b)
コード例 #4
0
ファイル: test_json.py プロジェクト: luizirber/odo
def test_multiple_jsonlines():
    a, b = '_test_a1.json', '_test_a2.json'
    try:
        with ignoring(OSError):
            os.remove(a)
        with ignoring(OSError):
            os.remove(b)
        with open(a, 'w') as f:
            json.dump(dat, f)
        with open(b'_test_a2.json', 'w') as f:
            json.dump(dat, f)
        r = resource('_test_a*.json')
        result = convert(list, r)
        assert len(result) == len(dat) * 2
    finally:
        with ignoring(OSError):
            os.remove(a)
        with ignoring(OSError):
            os.remove(b)
コード例 #5
0
ファイル: test_sql_csv.py プロジェクト: MoherX/odo
def test_into_sqlite():
    data = [('Alice', 100), ('Bob', 200)]
    ds = datashape.dshape('var * {name: string, amount: int}')

    with tmpfile('.db') as dbpath:
        with tmpfile('.csv') as csvpath:
            csv = into(csvpath, data, dshape=ds, has_header=False)
            sql = resource('sqlite:///%s::mytable' % dbpath, dshape=ds)
            with ignoring(NotImplementedError):
                append_csv_to_sql_table(sql, csv)
                assert into(list, sql) == data
コード例 #6
0
def tmpbcolz(*args, **kwargs):
    fn = '.%s.bcolz' % str(uuid.uuid1())
    r = resource(fn, *args, **kwargs)

    try:
        yield r
    finally:
        with ignoring(Exception):
            r.flush()
        if os.path.exists(fn):
            shutil.rmtree(fn)
コード例 #7
0
ファイル: test_h5py.py プロジェクト: MoherX/odo
def file(x):
    with tmpfile('.hdf5') as fn:
        f = h5py.File(fn)
        data = f.create_dataset('/data', data=x, chunks=True,
                                maxshape=(None,) + x.shape[1:])

        try:
            yield fn, f, data
        finally:
            with ignoring(Exception):
                f.close()
コード例 #8
0
ファイル: test_h5py.py プロジェクト: MoherX/odo
def test_drop_group():
    with tmpfile('.hdf5') as fn:
        f = h5py.File(fn)
        try:
            f.create_dataset('/group/data', data=x, chunks=True,
                             maxshape=(None,) + x.shape[1:])
            drop(f['/group'])
            assert '/group' not in f.keys()
        finally:
            with ignoring(Exception):
                f.close()
コード例 #9
0
ファイル: test_sql_csv.py プロジェクト: luizirber/odo
def test_into_sqlite():
    data = [('Alice', 100), ('Bob', 200)]
    ds = datashape.dshape('var * {name: string, amount: int}')

    with tmpfile('.db') as dbpath:
        with tmpfile('.csv') as csvpath:
            csv = into(csvpath, data, dshape=ds, has_header=False)
            sql = resource('sqlite:///%s::mytable' % dbpath, dshape=ds)
            with ignoring(NotImplementedError):
                append_csv_to_sql_table(sql, csv)
                assert into(list, sql) == data
コード例 #10
0
ファイル: test_bcolz.py プロジェクト: MoherX/odo
def tmpbcolz(*args, **kwargs):
    fn = '.%s.bcolz' % str(uuid.uuid1())
    r = resource(fn, *args, **kwargs)

    try:
        yield r
    finally:
        with ignoring(Exception):
            r.flush()
        if os.path.exists(fn):
            shutil.rmtree(fn)
コード例 #11
0
ファイル: test_h5py.py プロジェクト: pskyp/shareapplication
def test_drop_group():
    with tmpfile('.hdf5') as fn:
        f = h5py.File(fn)
        try:
            f.create_dataset('/group/data',
                             data=x,
                             chunks=True,
                             maxshape=(None, ) + x.shape[1:])
            drop(f['/group'])
            assert '/group' not in f.keys()
        finally:
            with ignoring(Exception):
                f.close()
コード例 #12
0
ファイル: test_h5py.py プロジェクト: pskyp/shareapplication
def file(x):
    with tmpfile('.hdf5') as fn:
        f = h5py.File(fn)
        data = f.create_dataset('/data',
                                data=x,
                                chunks=True,
                                maxshape=(None, ) + x.shape[1:])

        try:
            yield fn, f, data
        finally:
            with ignoring(Exception):
                f.close()
コード例 #13
0
def jslines(n=3):
    d = tempfile.mkdtemp()
    files = []
    dfc = df.copy()
    for i in range(n):
        _, fn = tempfile.mkstemp(suffix='.json', dir=d)
        dfc['id'] += i
        odo(dfc, 'jsonlines://%s' % fn)
        files.append(fn)

    yield d

    with ignoring(OSError):
        shutil.rmtree(d)
コード例 #14
0
ファイル: test_sparksql.py プロジェクト: MoherX/odo
def jslines(n=3):
    d = tempfile.mkdtemp()
    files = []
    dfc = df.copy()
    for i in range(n):
        _, fn = tempfile.mkstemp(suffix='.json', dir=d)
        dfc['id'] += i
        odo(dfc, 'jsonlines://%s' % fn)
        files.append(fn)

    yield d

    with ignoring(OSError):
        shutil.rmtree(d)
コード例 #15
0
ファイル: test_h5py.py プロジェクト: pskyp/shareapplication
def test_discover_on_data_with_object_in_record_name():
    data = np.array([(u'a', 1), (u'b', 2)],
                    dtype=[('lrg_object', unicode_dtype), ('an_int', 'int64')])
    with tmpfile('.hdf5') as fn:
        f = h5py.File(fn)
        try:
            f.create_dataset('/data', data=data)
        except:
            raise
        else:
            assert (discover(f['data']) == datashape.dshape(
                '2 * {lrg_object: string, an_int: int64}'))
        finally:
            with ignoring(Exception):
                f.close()
コード例 #16
0
ファイル: test_h5py.py プロジェクト: MoherX/odo
def test_discover_on_data_with_object_in_record_name():
    data = np.array([(u'a', 1), (u'b', 2)], dtype=[('lrg_object',
                                                    unicode_dtype),
                                                   ('an_int', 'int64')])
    with tmpfile('.hdf5') as fn:
        f = h5py.File(fn)
        try:
            f.create_dataset('/data', data=data)
        except:
            raise
        else:
            assert (discover(f['data']) ==
                    datashape.dshape('2 * {lrg_object: string, an_int: int64}'))
        finally:
            with ignoring(Exception):
                f.close()
コード例 #17
0
ファイル: spider.py プロジェクト: yihongfa/blaze
def _spider(resource_path, ignore, followlinks, hidden):
    resources = {}
    for filename in (os.path.join(resource_path, x)
                     for x in os.listdir(resource_path)):
        basename = os.path.basename(filename)
        if (basename.startswith(os.curdir) and not hidden or
                os.path.islink(filename) and not followlinks):
            continue
        if os.path.isdir(filename):
            new_resources = _spider(filename, ignore=ignore,
                                    followlinks=followlinks, hidden=hidden)
            if new_resources:
                resources[basename] = new_resources
        else:
            with ignoring(*ignore):
                resources[basename] = resource(filename)
    return resources
コード例 #18
0
ファイル: interactive.py プロジェクト: testmana2/blaze
from pandas import DataFrame, Series, Timestamp


from .expr import Expr, Symbol, ndim
from .dispatch import dispatch
from .compatibility import _strtypes


__all__ = ['Data', 'Table', 'into', 'to_html']


names = ('_%d' % i for i in itertools.count(1))
not_an_iterator = []


with ignoring(ImportError):
    import bcolz
    not_an_iterator.append(bcolz.carray)


with ignoring(ImportError):
    import pymongo
    not_an_iterator.append(pymongo.collection.Collection)
    not_an_iterator.append(pymongo.database.Database)


class InteractiveSymbol(Symbol):
    """Interactive data.

    The ``Data`` object presents a familiar view onto a variety of forms of
    data.  This user-level object provides an interactive experience to using
コード例 #19
0
ファイル: interactive.py プロジェクト: wegamekinglc/blaze
import numpy as np
from odo import resource, odo
from odo.utils import ignoring, copydoc
from odo.compatibility import unicode
from pandas import DataFrame, Series, Timestamp

from .expr import Expr, Symbol, ndim
from .dispatch import dispatch
from .compatibility import _strtypes

__all__ = ['Data', 'Table', 'into', 'to_html']

names = ('_%d' % i for i in itertools.count(1))
not_an_iterator = []

with ignoring(ImportError):
    import bcolz
    not_an_iterator.append(bcolz.carray)

with ignoring(ImportError):
    import pymongo
    not_an_iterator.append(pymongo.collection.Collection)
    not_an_iterator.append(pymongo.database.Database)


class InteractiveSymbol(Symbol):
    """Interactive data.

    The ``Data`` object presents a familiar view onto a variety of forms of
    data.  This user-level object provides an interactive experience to using
    Blaze's abstract expressions.