本文整理汇总了Python中blaze.expr.TableSymbol类的典型用法代码示例。如果您正苦于以下问题:Python TableSymbol类的具体用法?Python TableSymbol怎么用?Python TableSymbol使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TableSymbol类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_by_columns
def test_by_columns():
t = TableSymbol('t', '{name: string, amount: int32, id: int32}')
assert len(by(t['id'], t['amount'].sum()).fields) == 2
assert len(by(t['id'], t['id'].count()).fields) == 2
print(by(t, t.count()).fields)
assert len(by(t, t.count()).fields) == 4
示例2: test_traverse
def test_traverse():
t = TableSymbol('t', '{name: string, amount: int}')
assert t in list(t._traverse())
expr = t.amount.sum()
trav = list(expr._traverse())
assert builtins.any(t.amount.isidentical(x) for x in trav)
示例3: test_relabel_join
def test_relabel_join():
names = TableSymbol('names', '{first: string, last: string}')
siblings = join(names.relabel({'last': 'left'}),
names.relabel({'last': 'right'}), 'first')
assert siblings.fields == ['first', 'left', 'right']
示例4: test_by_columns
def test_by_columns():
t = TableSymbol("t", "{name: string, amount: int32, id: int32}")
assert len(by(t["id"], total=t["amount"].sum()).fields) == 2
assert len(by(t["id"], count=t["id"].count()).fields) == 2
print(by(t, count=t.count()).fields)
assert len(by(t, count=t.count()).fields) == 4
示例5: test_distinct_name
def test_distinct_name():
t = TableSymbol('t', '{id: int32, name: string}')
assert t.name.isidentical(t['name'])
assert t.distinct().name.isidentical(t.distinct()['name'])
assert t.id.distinct()._name == 'id'
assert t.name._name == 'name'
示例6: test_subterms
def test_subterms():
a = TableSymbol('a', '{x: int, y: int, z: int}')
assert list(a._subterms()) == [a]
assert set(a['x']._subterms()) == set([a, a['x']])
assert set(a['x'].map(inc, 'int')._subterms()) == \
set([a, a['x'], a['x'].map(inc, 'int')])
assert a in set((a['x'] + 1)._subterms())
示例7: test_symbol_projection_failures
def test_symbol_projection_failures():
t = TableSymbol("t", "10 * {name: string, amount: int}")
with pytest.raises(ValueError):
t._project(["name", "id"])
with pytest.raises(AttributeError):
t.foo
with pytest.raises(TypeError):
t._project(t.dshape)
示例8: test_Distinct
def test_Distinct():
t = TableSymbol('t', '{name: string, amount: int32}')
r = distinct(t['name'])
print(r.dshape)
assert r.dshape == dshape('var * {name: string}')
r = t.distinct()
assert r.dshape == t.dshape
示例9: test_traverse
def test_traverse():
t = TableSymbol('t', '{name: string, amount: int}')
assert t in list(t.traverse())
expr = t[t['amount'] < 0]['name']
trav = list(expr.traverse())
assert any(t['amount'].isidentical(x) for x in trav)
assert any((t['amount'] < 0).isidentical(x) for x in trav)
示例10: test_discover_dshape_symbol
def test_discover_dshape_symbol(ds):
t_ds = TableSymbol('t', dshape=ds)
assert t_ds.fields is not None
t_sch = TableSymbol('t', dshape=ds.subshape[0])
assert t_sch.fields is not None
assert t_ds.isidentical(t_sch)
示例11: test_sort
def test_sort():
t = TableSymbol('t', '{name: string, amount: int32, id: int32}')
s = t.sort('amount', ascending=True)
print(str(s))
assert eval(str(s)).isidentical(s)
assert s.schema == t.schema
assert t['amount'].sort().key == 'amount'
示例12: test_relabel
def test_relabel():
t = TableSymbol('t', '{name: string, amount: int32, id: int32}')
rl = t.relabel({'name': 'NAME', 'id': 'ID'})
assert eval(str(rl)).isidentical(rl)
print(rl.columns)
assert rl.columns == ['NAME', 'amount', 'ID']
示例13: test_length
def test_length():
t = TableSymbol('t', '10 * {name: string, amount: int}')
assert t.dshape == dshape('10 * {name: string, amount: int}')
assert len(t) == 10
assert len(t.name) == 10
assert len(t[['name']]) == 10
assert len(t.sort('name')) == 10
assert len(t.head(5)) == 5
assert len(t.head(50)) == 10
示例14: test_Distinct
def test_Distinct():
t = TableSymbol("t", "{name: string, amount: int32}")
r = distinct(t["name"])
print(r.dshape)
assert r.dshape == dshape("var * string")
assert r._name == "name"
r = t.distinct()
assert r.dshape == t.dshape
示例15: test_like
def test_like():
t = TableSymbol('t', '{name: string, city: string}')
data = [('Alice Smith', 'New York'),
('Bob Smith', 'Chicago'),
('Alice Walker', 'LA')]
assert list(compute(t.like(name='Alice*'), data)) == [data[0], data[2]]
assert list(compute(t.like(name='lice*'), data)) == []
assert list(compute(t.like(name='*Smith*'), data)) == [data[0], data[1]]
assert list(compute(t.like(name='*Smith*', city='New York'), data)) == [data[0]]