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)
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)
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)
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)
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)
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)
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'
def compute_up(sel, t, **kwargs): s = eval_str(sel.predicate.expr) return t.read_where(s)
def compute_up(sel, t, **kwargs): s = eval_str(sel.predicate._expr) return t.read_where(s)