def test_sql_add_table_columns(self): db = SQLDatabase(':memory:') db.add_table('test', columns=['a', 'b']) assert_equal(db.get_column('test', 'a').values, []) assert_equal(db.get_column('test', 'b').values, []) assert_equal(db.column_names('test'), ['a', 'b']) assert_equal(len(db), 1) assert_equal(db.table_names, ['test'])
def test_sql_add_table_from_data_dict(self): d = {'a': np.arange(10, 20), 'b': np.arange(20, 30)} db = SQLDatabase(':memory:') db.add_table('test', data=d) assert_equal(db.get_column('test', 'a').values, np.arange(10, 20)) assert_equal(db.get_column('test', 'b').values, np.arange(20, 30)) assert_equal(db.column_names('test'), ['a', 'b']) assert_equal(len(db), 1) assert_equal(db.table_names, ['test'])
def test_sql_add_table_from_data_ndarray(self): dtype = [('a', 'i4'), ('b', 'f8')] data = np.array([(1, 2.0), (3, 4.0), (5, 6.0), (7, 8.0)], dtype=dtype) db = SQLDatabase(':memory:') db.add_table('test', data=data) assert_equal(db.get_column('test', 'a').values, [1, 3, 5, 7]) assert_equal(db.get_column('test', 'b').values, [2.0, 4.0, 6.0, 8.0]) assert_equal(db.column_names('test'), ['a', 'b']) assert_equal(len(db), 1) assert_equal(db.table_names, ['test'])
def test_sql_add_column_name_and_data(self): db = SQLDatabase(':memory:') db.add_table('test') db.add_column('test', 'a', data=np.arange(10, 20)) db.add_column('test', 'b', data=np.arange(20, 30)) assert_equal(db.get_column('test', 'a').values, np.arange(10, 20)) assert_equal(db.get_column('test', 'b').values, np.arange(20, 30)) assert_equal(db.column_names('test'), ['a', 'b']) assert_equal(len(db), 1) assert_equal(db.table_names, ['test'])
def test_sqltable_add_row_add_columns(self): db = SQLDatabase(':memory:') db.add_table('test') db.add_column('test', 'a') db.add_column('test', 'b') db['test'].add_row(dict(a=1, b=2)) db['test'].add_row(dict(a=3, c=4), add_columns=False) db['test'].add_row(dict(a=5, d=6), add_columns=True) assert_equal(db.get_column('test', 'a').values, [1, 3, 5]) assert_equal(db.get_column('test', 'b').values, [2, None, None]) assert_equal(len(db), 1) assert_equal(db.table_names, ['test']) assert_equal(db.column_names('test'), ['a', 'b', 'd'])
def test_sqltable_add_column(self): db = SQLDatabase(':memory:') db.add_table('test') db['test'].add_column('a') db['test'].add_column('b') db['test'].add_column('c', data=[1, 2, 3]) assert_equal(db.get_column('test', 'a').values, [None, None, None]) assert_equal(db.get_column('test', 'b').values, [None, None, None]) assert_equal(db.get_column('test', 'c').values, [1, 2, 3]) assert_equal(len(db), 1) assert_equal(db.table_names, ['test']) assert_equal(db.column_names('test'), ['a', 'b', 'c']) assert_equal(len(db['test']), 3)
def test_sql_prop_column_names(self): db = SQLDatabase(':memory:') db.add_table('test') db.add_column('test', 'a', data=np.arange(10, 20)) db.add_column('test', 'b', data=np.arange(20, 30)) assert_equal(db.column_names('test'), ['a', 'b'])