예제 #1
0
파일: bcolz.py 프로젝트: hhuuggoo/blaze
def compute_one(sel, t, **kwargs):
    s = eval_str(sel.predicate.expr)
    try:
        return t.where(s)
    except (NotImplementedError, NameError):
        # numexpr may not be able to handle the predicate
        return compute_one(sel, iter(t), **kwargs)
예제 #2
0
파일: test_table.py 프로젝트: Casolt/blaze
def test_broadcast():
    from blaze.expr.arithmetic import Add, Eq, Mult, Le
    t = TableSymbol('t', '{x: int, y: int, z: int}')
    t2 = TableSymbol('t', '{a: int, b: int, c: int}')
    x = t['x']
    y = t['y']
    z = t['z']
    a = t2['a']
    b = t2['b']
    c = t2['c']

    assert str(broadcast(Add, x, y).expr) == 'x + y'
    assert broadcast(Add, x, y)._child.isidentical(t)

    c1 = broadcast(Add, x, y)
    c2 = broadcast(Mult, x, z)

    assert eval_str(broadcast(Eq, c1, c2).expr) == '(x + y) == (x * z)'
    assert broadcast(Eq, c1, c2)._child.isidentical(t)

    assert str(broadcast(Add, x, 1).expr) == 'x + 1'

    assert str(x <= y) == "t['x'] <= t['y']"
    assert str(x >= y) == "t['x'] >= t['y']"
    assert str(x | y) == "t['x'] | t['y']"
    assert str(x.__ror__(y)) == "t['y'] | t['x']"
    assert str(x.__rand__(y)) == "t['y'] & t['x']"

    with pytest.raises(ValueError):
        broadcast(Add, x, a)
예제 #3
0
def test_broadcast():
    from blaze.expr.arithmetic import Add, Eq, Mult, Le
    t = TableSymbol('t', '{x: int, y: int, z: int}')
    t2 = TableSymbol('t', '{a: int, b: int, c: int}')
    x = t['x']
    y = t['y']
    z = t['z']
    a = t2['a']
    b = t2['b']
    c = t2['c']

    assert str(broadcast(Add, x, y)._expr) == 'x + y'
    assert broadcast(Add, x, y)._child.isidentical(t)

    c1 = broadcast(Add, x, y)
    c2 = broadcast(Mult, x, z)

    assert eval_str(broadcast(Eq, c1, c2)._expr) == '(x + y) == (x * z)'
    assert broadcast(Eq, c1, c2)._child.isidentical(t)

    assert str(broadcast(Add, x, 1)._expr) == 'x + 1'

    assert str(x <= y) == "t.x <= t.y"
    assert str(x >= y) == "t.x >= t.y"
    assert str(x | y) == "t.x | t.y"
    assert str(x.__ror__(y)) == "t.y | t.x"
    assert str(x.__rand__(y)) == "t.y & t.x"

    with pytest.raises(ValueError):
        broadcast(Add, x, a)
예제 #4
0
파일: bcolz.py 프로젝트: vitan/blaze
def compute_up(expr, data, **kwargs):
    if data.nbytes < COMFORTABLE_MEMORY_SIZE:
        return compute_up(expr, data[:], **kwargs)
    s = eval_str(expr.predicate._expr)
    try:
        return data.where(s)
    except (NotImplementedError, NameError, AttributeError):
        # numexpr may not be able to handle the predicate
        return compute_up(expr, into(Iterator, data), **kwargs)
예제 #5
0
파일: bcolz.py 프로젝트: vitan/blaze
def compute_up(expr, data, **kwargs):
    if data.nbytes < COMFORTABLE_MEMORY_SIZE:
        return compute_up(expr, data[:], **kwargs)
    s = eval_str(expr.predicate._expr)
    try:
        return data.where(s)
    except (NotImplementedError, NameError, AttributeError):
        # numexpr may not be able to handle the predicate
        return compute_up(expr, into(Iterator, data), **kwargs)
예제 #6
0
def test_eval_str():
    expr = (x + y) * 3
    assert eval_str(expr) == '(x + y) * 3'

    assert eval_str(1) == '1'
    assert eval_str('Alice') == "'Alice'"
    assert "'Alice'" in eval_str(u'Alice')

    print(eval_str(-x))
    assert eval_str(-x) == '-x'
    assert '~' in eval_str(~x)
예제 #7
0
def test_eval_str():
    expr = (x + y) * 3
    assert eval_str(expr) == '(x + y) * 3'

    assert eval_str(1) == '1'
    assert eval_str('Alice') == "'Alice'"
    assert "'Alice'" in eval_str(u'Alice')

    print(eval_str(-x))
    assert eval_str(-x) == '-x'
    assert '~' in eval_str(~x)
예제 #8
0
def test_eval_str():
    expr = (x + y) * 3
    assert eval_str(expr) == "(x + y) * 3"

    assert eval_str(1) == "1"
    assert eval_str("Alice") == "'Alice'"
    assert "'Alice'" in eval_str(u"Alice")

    print(eval_str(-x))
    assert eval_str(-x) == "-x"

    assert "~" in eval_str(~b)
예제 #9
0
파일: test_table.py 프로젝트: chdoig/blaze
def test_columnwise():
    from blaze.expr.scalar import Add, Eq, Mult
    t = TableSymbol('t', '{x: int, y: int, z: int}')
    x = t['x']
    y = t['y']
    z = t['z']
    assert str(columnwise(Add, x, y).expr) == 'x + y'
    assert columnwise(Add, x, y).child.isidentical(t)

    c1 = columnwise(Add, x, y)
    c2 = columnwise(Mult, x, z)

    assert eval_str(columnwise(Eq, c1, c2).expr) == '(x + y) == (x * z)'
    assert columnwise(Eq, c1, c2).child.isidentical(t)

    assert str(columnwise(Add, x, 1).expr) == 'x + 1'
예제 #10
0
def compute_up(sel, t, **kwargs):
    s = eval_str(sel.predicate.expr)
    return t.read_where(s)
예제 #11
0
def compute_up(sel, t, **kwargs):
    s = eval_str(sel.predicate._expr)
    return t.read_where(s)