Example #1
0
def test_pyfunc_works_with_invalid_python_names():
    x = symbol("x-y.z", "int")
    f = lambdify([x], x + 1)
    assert f(1) == 2

    t = symbol("t", '{"x.y": int, "y z": int}')
    f = lambdify([t], t.x_y + t.y_z)
    assert f((1, 2)) == 3
Example #2
0
def test_pyfunc_works_with_invalid_python_names():
    x = symbol('x-y.z', 'int')
    f = lambdify([x], x + 1)
    assert f(1) == 2

    t = symbol('t', '{"x.y": int, "y z": int}')
    f = lambdify([t], t.x_y + t.y_z)
    assert f((1, 2)) == 3
Example #3
0
def test_not():
    x = symbol("x", "bool")
    f = lambdify([x], ~x)
    r = f(True)
    assert isinstance(r, bool) and not r

    r = f(False)
    assert isinstance(r, bool) and r
Example #4
0
def test_not():
    x = symbol('x', 'bool')
    f = lambdify([x], ~x)
    r = f(True)
    assert isinstance(r, bool) and not r

    r = f(False)
    assert isinstance(r, bool) and r
Example #5
0
def test_broadcast_collect():
    t = symbol("t", "var * {x: int, y: int, z: int, when: datetime}")

    expr = t.distinct()
    expr = expr.x + 2 * expr.y
    expr = expr.distinct()

    result = broadcast_collect(expr)

    expected = t.distinct()
    expected = broadcast(expected.x + 2 * expected.y, [expected])
    expected = expected.distinct()

    assert result.isidentical(expected)
Example #6
0
def test_broadcast_collect():
    t = symbol('t', 'var * {x: int, y: int, z: int, when: datetime}')

    expr = t.distinct()
    expr = expr.x + 2 * expr.y
    expr = expr.distinct()

    result = broadcast_collect(expr)

    expected = t.distinct()
    expected = broadcast(expected.x + 2 * expected.y, [expected])
    expected = expected.distinct()

    assert result.isidentical(expected)
Example #7
0
def test_usub():
    x = symbol("x", "float64")
    f = lambdify([x], -x)
    assert f(1.0) == -1.0
Example #8
0
import datetime

from blaze.compute.pyfunc import symbol, lambdify, cos, math, broadcast
from blaze.compute.pyfunc import _print_python
from blaze.expr.broadcast import broadcast_collect


t = symbol("t", "{x: int, y: int, z: int, when: datetime}")


def test_simple():
    f = lambdify([t], t.x + t.y)
    assert f((1, 2, 3, 4)) == 1 + 2

    f = lambdify([t.x, t.y], t.x + t.y)
    assert f(1, 2) == 1 + 2


def test_datetime():
    f = lambdify([t], t.x + t.when.year)

    assert f((1, 2, 3, datetime.datetime(2000, 1, 1))) == 1 + 2000


def inc(x):
    return x + 1


def test_map():
    f = lambdify([t], t.x + t.y.map(inc, "int"))
    assert f((1, 2, 3, 4)) == 1 + inc(2)
Example #9
0
def test_usub():
    x = symbol('x', 'float64')
    f = lambdify([x], -x)
    assert f(1.0) == -1.0
Example #10
0
import datetime

from blaze.compute.pyfunc import symbol, lambdify, cos, math, broadcast
from blaze.compute.pyfunc import _print_python
from blaze.expr.broadcast import broadcast_collect


t = symbol('t', '{x: int, y: int, z: int, when: datetime}')


def test_simple():
    f = lambdify([t], t.x + t.y)
    assert f((1, 2, 3, 4)) == 1 + 2

    f = lambdify([t.x, t.y], t.x + t.y)
    assert f(1, 2) == 1 + 2


def test_datetime():
    f = lambdify([t], t.x + t.when.year)

    assert f((1, 2, 3, datetime.datetime(2000, 1, 1))) == 1 + 2000


def inc(x):
    return x + 1


def test_map():
    f = lambdify([t], t.x + t.y.map(inc, 'int'))
    assert f((1, 2, 3, 4)) == 1 + inc(2)
Example #11
0
def test_usub():
    x = symbol('x', 'float64')
    f = lambdify([x], -x)
    assert f(1.0) == -1.0
Example #12
0
import datetime

from blaze.compute.pyfunc import symbol, lambdify, cos, math, broadcast
from blaze.compute.pyfunc import _print_python
from blaze.expr.broadcast import broadcast_collect

t = symbol('t', '{x: int, y: int, z: int, when: datetime}')


def test_simple():
    f = lambdify([t], t.x + t.y)
    assert f((1, 2, 3, 4)) == 1 + 2

    f = lambdify([t.x, t.y], t.x + t.y)
    assert f(1, 2) == 1 + 2


def test_datetime():
    f = lambdify([t], t.x + t.when.year)

    assert f((1, 2, 3, datetime.datetime(2000, 1, 1))) == 1 + 2000


def inc(x):
    return x + 1


def test_map():
    f = lambdify([t], t.x + t.y.map(inc, 'int'))
    assert f((1, 2, 3, 4)) == 1 + inc(2)