def test_column(sql): t = Table(sql) r = compute(t['x']) assert r == [1, 10, 100] assert compute(t[['x']]) == [(1,), (10,), (100,)] assert compute(t.count()) == 3
def test_column(): data = [(1, 2), (10, 20), (100, 200)] sql = SQL('sqlite:///:memory:', 'foo', schema='{x: int, y: int}') sql.extend(data) t = Table(sql) assert compute(t['x']) == [1, 10, 100] assert compute(t[['x']]) == [(1,), (10,), (100,)] assert compute(t.count()) == 3
def build_table(table_name, rows): """build the table to use in our example. if already built just open it""" if not os.path.exists(table_name): ds = 'x, {i: int64; f: float64}' p = params(clevel=5, storage=table_name) t = Table([], dshape=ds, params=p) for i in xrange(rows): t.append((i, random())) t.commit() else: t = open(table_name) return t
def test_all_construct(): # Assert that the pretty pritner works for all of the # toplevel structures expected_ds = dshape('3, int') a = NDArray([1,2,3]) str(a) repr(a) a.datashape._equal(expected_ds) a = Array([1,2,3]) str(a) repr(a) a.datashape._equal(expected_ds) a = NDTable([(1, 1)]) str(a) repr(a) #a.datashape._equal(expected_ds) a = Table([(1, 1)]) str(a) repr(a)
def test_expr_client_interactive(): ec = Client('localhost:6363', 'accounts') t = Table(ec) assert compute(t.name) == ['Alice', 'Bob'] assert (into(set, compute(by(t.name, min=t.amount.min(), max=t.amount.max()))) == set([('Alice', 100, 100), ('Bob', 200, 200)]))
def test_string_dataset(tmpcsv): raw = 'a,b,2.0\nc,1999,3.0\nd,3.0,4.0' with open(tmpcsv, mode='w') as f: f.write(raw) csv = CSV(tmpcsv, columns=list('xyz')) t = Table(csv) x = into(list, t) assert x == [('a', 'b', 2.0), ('c', '1999', 3.0), ('d', '3.0', 4.0)]
def test_simple(): if not os.path.exists('./noaa_data'): p = params(clevel=5, storage='./noaa_data') t = Table([], dshape='{f0: int, f1:int, f2:int, f3:float}', params=p) # TODO: chunkwise copy t.append(adapter[:]) t.commit() else: t = open('ctable://noaa_data') print '--------------------------------------' print 'mean', mean(t, 'f3') print 'std', std(t, 'f2') print '--------------------------------------' qs1 = select(t, lambda x: x > 80000, 'f0') qs2 = select2(t, lambda x,y: x > y, ['f0', 'f1']) result = t[qs1]
def test_custom_dshape(): from blaze import RecordDecl, derived from blaze import int32 class CustomStock(RecordDecl): max = int32 min = int32 @derived def mid(self): return (self.min + self.max) / 2 a = Table([('GOOG', 120, 153)], CustomStock)
def test_simple(): if not os.path.exists('./noaa_data'): p = params(clevel=5, storage='./noaa_data') t = Table([], dshape='{f0: int, f1:int, f2:int, f3:float}', params=p) # TODO: chunkwise copy t.append(adapter[:]) t.commit() else: t = open('ctable://noaa_data') print '--------------------------------------' print 'mean', mean(t, 'f3') print 'std', std(t, 'f2') print '--------------------------------------' qs1 = select(t, lambda x: x > 80000, 'f0') qs2 = select2(t, lambda x, y: x > y, ['f0', 'f1']) result = t[qs1]
def test_different_schema_raises(): with tmpfile('.csv') as filename: df = pd.DataFrame(np.random.randn(10, 2)) df.to_csv(filename, index=False, header=False) with pytest.raises(TypeError): Table(CSV(filename), columns=list('ab'))