Exemplo n.º 1
0
 def test_create_index_fails(self, sql):
     with pytest.raises(KeyError):
         create_index(sql, 'z', name='zidx')
     with pytest.raises(ValueError):
         create_index(sql, 'x')
     with pytest.raises(ValueError):
         create_index(sql, 'z')
Exemplo n.º 2
0
def test_create_index_fails(sql):
    with pytest.raises(KeyError):
        create_index(sql, "z", name="zidx")
    with pytest.raises(ValueError):
        create_index(sql, "x")
    with pytest.raises(ValueError):
        create_index(sql, "z")
Exemplo n.º 3
0
def test_create_index(pyt):
    create_index(pyt, 'id')
    assert 'id' in pyt.colindexes
Exemplo n.º 4
0
def test_create_multiple_indexes_fails(pyt):
    with pytest.raises(ValueError):
        create_index(pyt, ['id', 'blarg'])

    with pytest.raises(ValueError):
        create_index(pyt, ['foo', 'bar'])
Exemplo n.º 5
0
def test_create_index(pyt):
    create_index(pyt, 'id')
    assert 'id' in pyt.colindexes
Exemplo n.º 6
0
 def test_fails_when_using_not_list_of_tuples_or_strings(self, mongo_idx):
     from pymongo import DESCENDING
     with pytest.raises(TypeError):
         create_index(mongo_idx.tmp_collection, [['id', DESCENDING]])
Exemplo n.º 7
0
 def test_create_composite_index(self, mongo_idx):
     create_index(mongo_idx.tmp_collection, ['id', 'amount'], name='c_idx')
     assert 'c_idx' in mongo_idx.tmp_collection.index_information()
Exemplo n.º 8
0
 def test_create_index_unique(self, sql):
     create_index(sql, 'y', name='y_idx', unique=True)
     assert len(sql.indexes) == 1
     idx = first(sql.indexes)
     assert idx.unique
     assert idx.columns.y == sql.c.y
Exemplo n.º 9
0
 def test_create_index(self, mongo_idx):
     create_index(mongo_idx.tmp_collection, 'id', name='idx_id')
     assert 'idx_id' in mongo_idx.tmp_collection.index_information()
Exemplo n.º 10
0
 def test_create_composite_index(self, mongo_idx):
     create_index(mongo_idx.tmp_collection, ['id', 'amount'])
     assert 'id_1_amount_1' in mongo_idx.tmp_collection.index_information()
Exemplo n.º 11
0
from blaze import CSV, Table
csv = CSV('hmda_lar-2012.csv')  # Open the CSV file
t = Table(csv)                  # Interact with CSV file using interactive Table object

columns = ['action_taken_name', 'agency_abbr', 'applicant_ethnicity_name',
           'applicant_race_name_1', 'applicant_sex_name', 'county_name',
           'loan_purpose_name', 'state_abbr']

t = t[columns]

t2 = t[t.state_abbr == 'NY']

from blaze import into, by
from pandas import DataFrame
# Group on action_taken_name, count each group
print into(DataFrame, t2.action_taken_name.count_values())

from blaze import SQL
sql = SQL('sqlite:///hmda.db', 'data', schema=t.schema) # A SQLite database
into(sql, t)  # Migrate data

sqlTable = Table(sql)

from blaze import create_index
create_index(sql, 'state_abbr', name='state_abbr_index')

t2 = sqlTable[sqlTable.state_abbr == 'NY']

print into(DataFrame, t2.action_taken_name.count_values())
Exemplo n.º 12
0
def test_composite_index_fails_with_existing_columns(sql):
    with pytest.raises(KeyError):
        create_index(sql, ["x", "z", "bizz"], name="idx_name")
Exemplo n.º 13
0
def test_composite_index_fails(sql):
    with pytest.raises(KeyError):
        create_index(sql, ["z", "bizz"], name="idx_name")
Exemplo n.º 14
0
def test_composite_index(sql):
    create_index(sql, ["x", "y"], name="idx_xy")
    with pytest.raises(OperationalError):
        create_index(sql, ["x", "y"], name="idx_xy")
Exemplo n.º 15
0
def test_create_index_unique(sql):
    create_index(sql, "y", name="y_idx", unique=True)
    assert len(sql.data.indexes) == 1
    idx = first(sql.data.indexes)
    assert idx.unique
    assert idx.columns.y == sql.data.c.y
Exemplo n.º 16
0
def test_create_multiple_indexes_fails(pyt):
    with pytest.raises(ValueError):
        create_index(pyt, ['id', 'blarg'])

    with pytest.raises(ValueError):
        create_index(pyt, ['foo', 'bar'])
Exemplo n.º 17
0
 def test_create_index(self, sql):
     create_index(sql, 'x', name='idx')
     with pytest.raises(OperationalError):
         create_index(sql, 'x', name='idx')
Exemplo n.º 18
0
 def test_create_index_single_element_list(self, mongo_idx):
     create_index(mongo_idx.tmp_collection, ['id'], name='idx_id')
     assert 'idx_id' in mongo_idx.tmp_collection.index_information()
Exemplo n.º 19
0
 def test_composite_index_fails(self, sql):
     with pytest.raises(KeyError):
         create_index(sql, ['z', 'bizz'], name='idx_name')
Exemplo n.º 20
0
 def test_create_composite_index(self, mongo_idx):
     create_index(mongo_idx.tmp_collection, ['id', 'amount'], name='c_idx')
     assert 'c_idx' in mongo_idx.tmp_collection.index_information()
Exemplo n.º 21
0
 def test_create_index_single_element_list(self, mongo_idx):
     create_index(mongo_idx.tmp_collection, ['id'], name='idx_id')
     assert 'idx_id' in mongo_idx.tmp_collection.index_information()
Exemplo n.º 22
0
 def test_create_composite_index_params(self, mongo_idx):
     from pymongo import ASCENDING, DESCENDING
     create_index(mongo_idx.tmp_collection, [('id', ASCENDING),
                                             ('amount', DESCENDING)],
                  name='c_idx')
     assert 'c_idx' in mongo_idx.tmp_collection.index_information()
Exemplo n.º 23
0
 def test_create_composite_index_params(self, mongo_idx):
     from pymongo import ASCENDING, DESCENDING
     create_index(mongo_idx.tmp_collection,
                  [('id', ASCENDING), ('amount', DESCENDING)],
                  name='c_idx')
     assert 'c_idx' in mongo_idx.tmp_collection.index_information()
Exemplo n.º 24
0
 def test_fails_when_using_not_list_of_tuples_or_strings(self, mongo_idx):
     from pymongo import DESCENDING
     with pytest.raises(TypeError):
         create_index(mongo_idx.tmp_collection, [['id', DESCENDING]])
Exemplo n.º 25
0
 def test_create_index_with_unique(self, mongo_idx):
     coll = mongo_idx.tmp_collection
     create_index(coll, 'id', unique=True, name='c_idx')
     assert coll.index_information()['c_idx']['unique']
Exemplo n.º 26
0
 def test_create_index_with_unique(self, mongo_idx):
     coll = mongo_idx.tmp_collection
     create_index(coll, 'id', unique=True, name='c_idx')
     assert coll.index_information()['c_idx']['unique']
Exemplo n.º 27
0
def test_create_multiple_indexes(pyt):
    create_index(pyt, ['id', 'amount'])
    assert len(pyt.colindexes) == 2
    assert 'id' in pyt.colindexes
    assert 'amount' in pyt.colindexes
Exemplo n.º 28
0
def test_create_index(pyt):
    create_index(pyt, "id")
    assert "id" in pyt.colindexes
Exemplo n.º 29
0
def test_create_index_fails(pyt):
    with pytest.raises(AttributeError):
        create_index(pyt, 'no column here!')
Exemplo n.º 30
0
def test_create_multiple_indexes(pyt):
    create_index(pyt, ["id", "amount"])
    assert len(pyt.colindexes) == 2
    assert "id" in pyt.colindexes
    assert "amount" in pyt.colindexes
Exemplo n.º 31
0
def test_create_multiple_indexes(pyt):
    create_index(pyt, ['id', 'amount'])
    assert len(pyt.colindexes) == 2
    assert 'id' in pyt.colindexes
    assert 'amount' in pyt.colindexes
Exemplo n.º 32
0
def test_create_multiple_indexes_fails(pyt):
    with pytest.raises(ValueError):
        create_index(pyt, ["id", "blarg"])

    with pytest.raises(ValueError):
        create_index(pyt, ["foo", "bar"])
Exemplo n.º 33
0
def test_create_index_fails(pyt):
    with pytest.raises(AttributeError):
        create_index(pyt, 'no column here!')
Exemplo n.º 34
0
def test_create_index(sql, cols):
    create_index(sql, cols, name='idx')
    with pytest.raises(OperationalError):
        create_index(sql, cols, name='idx')
Exemplo n.º 35
0
def test_create_index(sql, cols):
    create_index(sql, cols, name='idx')
    with pytest.raises(OperationalError):
        create_index(sql, cols, name='idx')
Exemplo n.º 36
0
 def test_create_composite_index(self, mongo_idx):
     create_index(mongo_idx.tmp_collection, ['id', 'amount'])
     assert 'id_1_amount_1' in mongo_idx.tmp_collection.index_information()
Exemplo n.º 37
0
 def test_composite_index(self, sql):
     create_index(sql, ['x', 'y'], name='idx_xy')
     with pytest.raises(OperationalError):
         create_index(sql, ['x', 'y'], name='idx_xy')
Exemplo n.º 38
0
 def test_create_index(self, mongo_idx):
     create_index(mongo_idx.tmp_collection, 'id', name='idx_id')
     assert 'idx_id' in mongo_idx.tmp_collection.index_information()
Exemplo n.º 39
0
 def test_composite_index_fails_with_existing_columns(self, sql):
     with pytest.raises(KeyError):
         create_index(sql, ['x', 'z', 'bizz'], name='idx_name')
Exemplo n.º 40
0
 def test_create_composite_index_params(self, mongo_idx):
     create_index(mongo_idx.tmp_collection,
                  [('id', ASCENDING), ('amount', DESCENDING)])
     assert 'id_1_amount_-1' in mongo_idx.tmp_collection.index_information()