def test_into_ctable_list_datetimes(): from datetime import datetime L = [datetime(2012, 1, 1), datetime(2013, 2, 2)] b = into(bcolz.carray, L) assert np.issubdtype(b.dtype, np.datetime64) assert list(into(Iterator, b)) == L
def test_into_bcolz_from_many_numpy_arrays(): x = np.array([(1, 'Hello'), (2, 'abc')], dtype=[('num', 'i4'), ('name', 'S5')]) b = into(bcolz.ctable, x) assert len(b) == len(x) b = into(b, x) assert len(b) == 2 * len(x)
def test_into_chunks(): from blaze.compute.numpy import chunks, compute_up from blaze.compute.chunks import chunks, compute_up, ChunkIterator from blaze import into x = np.array([(int(i), float(i)) for i in range(100)], dtype=[('a', np.int32), ('b', np.float32)]) cs = chunks(x, chunksize=10) b1 = into(bcolz.ctable, ChunkIterator(cs)) b2 = into(bcolz.ctable, x) assert str(b1) == str(b2)
def test_selection_head(): b = into(bcolz.ctable, ((i, i + 1, float(i)**2) for i in range(10000)), names=['a', 'b', 'c']) t = Symbol('t', 'var * {a: int32, b: int32, c: float64}') assert compute((t.a < t.b).all(), b) == True assert list(compute(t[t.a < t.b].a.head(10), b)) == list(range(10)) assert list(compute(t[t.a > t.b].a.head(10), b)) == [] assert into([], compute(t[t.a + t.b > t.c], b)) == [(0, 1, 0), (1, 2, 1), (2, 3, 4)] assert len(compute(t[t.a + t.b > t.c].head(10), b)) # non-empty assert len(compute(t[t.a + t.b < t.c].head(10), b)) # non-empty
def test_selection_head(): b = into(bcolz.ctable, ((i, i + 1, float(i)**2) for i in range(10000)), names=['a', 'b', 'c']) t = TableSymbol('t', '{a: int32, b: int32, c: float64}') assert compute((t.a < t.b).all(), b) == True assert list(compute(t[t.a < t.b].a.head(10), b)) == list(range(10)) assert list(compute(t[t.a > t.b].a.head(10), b)) == [] assert into([], compute(t[t.a + t.b > t.c], b)) == [(0, 1, 0), (1, 2, 1), (2, 3, 4)] assert len(compute(t[t.a + t.b > t.c].head(10), b)) # non-empty assert len(compute(t[t.a + t.b < t.c].head(10), b)) # non-empty
def test_into_ctable_numpy(): assert str( into(bcolz.ctable, np.array([(1, 1.0), (2, 2.0), (3, 3.0)], dtype=[("a", np.int32), ("b", np.float32)])) ) == str( bcolz.ctable( [np.array([1, 2, 3], dtype=np.int32), np.array([1.0, 2.0, 3.0], dtype=np.float32)], names=["a", "b"] ) )
def test_into_ctable_DataFrame(): df = DataFrame([[1, "Alice"], [2, "Bob"], [3, "Charlie"]], columns=["id", "name"]) b = into(bcolz.ctable, df) assert list(b.names) == list(df.columns) assert list(b["id"]) == [1, 2, 3] print(b["name"]) print(b["name"][0]) print(type(b["name"][0])) assert list(b["name"]) == ["Alice", "Bob", "Charlie"]
def test_into_ctable_DataFrame(): df = DataFrame([[1, 'Alice'], [2, 'Bob'], [3, 'Charlie']], columns=['id', 'name']) b = into(bcolz.ctable, df) assert list(b.names) == list(df.columns) assert list(b['id']) == [1, 2, 3] print(b['name']) print(b['name'][0]) print(type(b['name'][0])) assert list(b['name']) == ['Alice', 'Bob', 'Charlie']
def test_into_ctable_DataFrame(): df = DataFrame([[1, 'Alice'], [2, 'Bob'], [3, 'Charlie']], columns=['id', 'name']) ds = dshape('var * {id: int32, name: string[7, "U32"]}') b = into(bcolz.ctable, df, dshape=ds) assert list(b.names) == list(df.columns) assert list(b['id']) == [1, 2, 3] assert list(b['name']) == ['Alice', 'Bob', 'Charlie'] assert discover(b).measure == ds.measure
def test_into_ndarray_ctable(): assert str(into(np.ndarray, b)) == \ str(np.array([(1, 1.), (2, 2.), (3, 3.)], dtype=[('a', int), ('b', float)]))
def test_into_ctable_numpy(): assert str(into(bcolz.ctable, np.array([(1, 1.), (2, 2.), (3, 3.)], dtype=[('a', np.int32), ('b', np.float32)]))) == \ str(bcolz.ctable([np.array([1, 2, 3], dtype=np.int32), np.array([1., 2., 3.], dtype=np.float32)], names=['a', 'b']))
def test_into_ctable_list(): b = into(bcolz.ctable, [(1, 1.), (2, 2.), (3, 3.)], names=['a', 'b']) assert list(b['a']) == [1, 2, 3] assert b.names == ['a', 'b']
def test_into_ctable_list_datetimes(): from datetime import datetime b = into(bcolz.carray, [datetime(2012, 1, 1), datetime(2013, 2, 2)]) assert np.issubdtype(b.dtype, np.datetime64)
def test_into_ctable_iterator(): b = into(bcolz.ctable, iter([(1, 1.), (2, 2.), (3, 3.)]), names=['a', 'b']) assert list(b['a']) == [1, 2, 3] assert b.names == ['a', 'b']
def test_into_DataFrame_ctable(): result = into(DataFrame(), b) expected = DataFrame([[1, 1.], [2, 2.], [3, 3.]], columns=['a', 'b']) assert str(result) == str(expected)
def test_into_list_carray(): assert into([], b['a']) == [1, 2, 3]
def test_into_list_ctable(): assert into([], b) == [(1, 1.), (2, 2.), (3, 3.)]
def test_into_ndarray_ctable(): assert str(into(np.ndarray, b)) == str(np.array([(1, 1.0), (2, 2.0), (3, 3.0)], dtype=[("a", int), ("b", float)]))
def test_into_ndarray_carray(): assert str(into(np.ndarray, b['a'])) == \ str(np.array([1, 2, 3]))
def test_into_DataFrame_ctable(): result = into(DataFrame(), b) expected = DataFrame([[1, 1.0], [2, 2.0], [3, 3.0]], columns=["a", "b"]) assert str(result) == str(expected)
def test_chunks(): assert len(list(chunks(b, chunksize=2))) == 2 assert (next(chunks(b, chunksize=2)) == into(np.array(0), b)[:2]).all()
def test_into_ctable_list(): b = into(bcolz.ctable, [(1, 1.0), (2, 2.0), (3, 3.0)], names=["a", "b"]) assert list(b["a"]) == [1, 2, 3] assert b.names == ["a", "b"]
def test_into_ctable_iterator(): b = into(bcolz.ctable, iter([(1, 1.0), (2, 2.0), (3, 3.0)]), names=["a", "b"]) assert list(b["a"]) == [1, 2, 3] assert b.names == ["a", "b"]