def _operator_helper(self, other, op, reversed=False, isSop=False): if isSop: # single operand operators return self.map(lambda x: op(x)) elif not isinstance(other, ptype.PType): if reversed: return self.map(lambda x: op(other, x)) else: return self.map(lambda x: op(x, other)) else: return self.map(lambda x, other: op(x, other), other)
def test_scalar_ops(data): from operator import add, sub, mul, truediv for op in (add, sub, mul, truediv): assert eq(compute(op(t.amount, 10), data), op(x['amount'], 10)) assert eq(compute(op(t.amount, t.id), data), op(x['amount'], x['id'])) assert eq(compute(op(10.0, t.amount), data), op(10.0, x['amount'])) assert eq(compute(op(10, t.amount), data), op(10, x['amount']))
def test_failing_floordiv(data): from operator import floordiv as op with pytest.raises(TypeError): assert eq(compute(op(t.amount, 10), data), op(x['amount'], 10)) with pytest.raises(TypeError): assert eq(compute(op(t.amount, t.id), data), op(x['amount'], x['id'])) with pytest.raises(TypeError): assert eq(compute(op(10.0, t.amount), data), op(10.0, x['amount'])) with pytest.raises(TypeError): assert eq(compute(op(10, t.amount), data), op(10, x['amount']))