當前位置: 首頁>>代碼示例>>Python>>正文


Python expr.Symbol類代碼示例

本文整理匯總了Python中blaze.expr.Symbol的典型用法代碼示例。如果您正苦於以下問題:Python Symbol類的具體用法?Python Symbol怎麽用?Python Symbol使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Symbol類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_relabel_join

def test_relabel_join():
    names = Symbol('names', 'var * {first: string, last: string}')

    siblings = join(names.relabel({'last': 'left'}),
                    names.relabel({'last': 'right'}), 'first')

    assert siblings.fields == ['first', 'left', 'right']
開發者ID:EGQM,項目名稱:blaze,代碼行數:7,代碼來源:test_symbol.py

示例2: test_by_columns

def test_by_columns():
    t = Symbol('t', 'var * {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
開發者ID:EGQM,項目名稱:blaze,代碼行數:7,代碼來源:test_symbol.py

示例3: test_subterms

def test_subterms():
    a = Symbol('a', 'var * {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())
開發者ID:EGQM,項目名稱:blaze,代碼行數:7,代碼來源:test_symbol.py

示例4: test_distinct_name

def test_distinct_name():
    t = Symbol('t', 'var * {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'
開發者ID:EGQM,項目名稱:blaze,代碼行數:7,代碼來源:test_symbol.py

示例5: test_keepdims

def test_keepdims():
    x = Symbol('x', '5 * 3 * float32')
    assert x.sum(axis=0, keepdims=True).dshape == dshape('1 * 3 * float32')
    assert x.sum(axis=1, keepdims=True).dshape == dshape('5 * 1 * float32')
    assert x.sum(axis=(0, 1), keepdims=True).dshape == dshape('1 * 1 * float32')

    assert x.std(axis=0, keepdims=True).shape == (1, 3)
開發者ID:Back2Basics,項目名稱:blaze,代碼行數:7,代碼來源:test_reductions.py

示例6: test_traverse

def test_traverse():
    t = Symbol('t', 'var * {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)
開發者ID:EGQM,項目名稱:blaze,代碼行數:7,代碼來源:test_symbol.py

示例7: test_nelements_array

def test_nelements_array():
    t = Symbol('t', '5 * 4 * 3 * float64')
    x = np.random.randn(*t.shape)
    result = compute(t.nelements(axis=(0, 1)), x)
    np.testing.assert_array_equal(result, np.array([20, 20, 20]))

    result = compute(t.nelements(axis=1), x)
    np.testing.assert_array_equal(result, 4 * np.ones((5, 3)))
開發者ID:Back2Basics,項目名稱:blaze,代碼行數:8,代碼來源:test_numpy_compute.py

示例8: test_symbol_projection_failures

def test_symbol_projection_failures():
    t = Symbol('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)
開發者ID:EGQM,項目名稱:blaze,代碼行數:8,代碼來源:test_symbol.py

示例9: test_Distinct

def test_Distinct():
    t = Symbol('t', 'var * {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
開發者ID:EGQM,項目名稱:blaze,代碼行數:9,代碼來源:test_symbol.py

示例10: test_sort

def test_sort():
    t = Symbol('t', 'var * {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'
開發者ID:EGQM,項目名稱:blaze,代碼行數:9,代碼來源:test_symbol.py

示例11: test_like

def test_like():
    t = Symbol('t', 'var * {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]]
開發者ID:Back2Basics,項目名稱:blaze,代碼行數:10,代碼來源:test_python_compute.py

示例12: test_serializable

def test_serializable():
    t = Symbol('t', 'var * {id: int, name: string, amount: int}')
    import pickle
    t2 = pickle.loads(pickle.dumps(t))

    assert t.isidentical(t2)

    s = Symbol('t', 'var * {id: int, city: string}')
    expr = join(t[t.amount < 0], s).sort('id').city.head()
    expr2 = pickle.loads(pickle.dumps(expr))

    assert expr.isidentical(expr2)
開發者ID:EGQM,項目名稱:blaze,代碼行數:12,代碼來源:test_symbol.py

示例13: test_length

def test_length():
    t = Symbol('t', '10 * {name: string, amount: int}')
    s = Symbol('s', 'var * {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
    with pytest.raises(ValueError):
        len(s)
開發者ID:EGQM,項目名稱:blaze,代碼行數:12,代碼來源:test_symbol.py

示例14: test_leaves

def test_leaves():
    t = Symbol('t', 'var * {id: int32, name: string}')
    v = Symbol('v', 'var * {id: int32, city: string}')
    x = symbol('x', 'int32')

    assert t._leaves() == [t]
    assert t.id._leaves() == [t]
    assert by(t.name, count=t.id.nunique())._leaves() == [t]
    assert join(t, v)._leaves() == [t, v]
    assert join(v, t)._leaves() == [v, t]

    assert (x + 1)._leaves() == [x]
開發者ID:EGQM,項目名稱:blaze,代碼行數:12,代碼來源:test_symbol.py

示例15: test_relabel

def test_relabel():
    t = Symbol('t', 'var * {name: string, amount: int32, id: int32}')

    rl = t.relabel({'name': 'NAME', 'id': 'ID'})
    rlc = t['amount'].relabel({'amount': 'BALANCE'})

    assert eval(str(rl)).isidentical(rl)

    print(rl.fields)
    assert rl.fields == ['NAME', 'amount', 'ID']

    assert not isscalar(rl.dshape.measure)
    assert isscalar(rlc.dshape.measure)
開發者ID:EGQM,項目名稱:blaze,代碼行數:13,代碼來源:test_symbol.py


注:本文中的blaze.expr.Symbol類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。