From 69dd64d5c6d700e8f59715cfaafe997845bb6ff8 Mon Sep 17 00:00:00 2001 From: Phillip Cloud <417981+cpcloud@users.noreply.github.com> Date: Mon, 16 May 2022 11:38:17 -0400 Subject: [PATCH] feat(datafusion): implement negate --- ibis/backends/datafusion/compiler.py | 10 ++++++++++ ibis/backends/tests/test_numeric.py | 1 - 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ibis/backends/datafusion/compiler.py b/ibis/backends/datafusion/compiler.py index 8ad4194057de..df2dd60b8eac 100644 --- a/ibis/backends/datafusion/compiler.py +++ b/ibis/backends/datafusion/compiler.py @@ -6,6 +6,7 @@ import pyarrow as pa import ibis.common.exceptions as com +import ibis.expr.datatypes as dt import ibis.expr.operations as ops import ibis.expr.types as ir from ibis.backends.datafusion.datatypes import to_pyarrow_type @@ -392,6 +393,15 @@ def not_contains(op, expr): return df.functions.in_list(value, options, negated=True) +@translate.register(ops.Negate) +def negate(op, expr): + op_arg = op.arg + arg = translate(op_arg) + if op_arg.type() == dt.boolean: + return ~arg + return df.lit(-1) * arg + + @translate.register(ops.ElementWiseVectorizedUDF) def elementwise_udf(op, expr): udf = df.udf( diff --git a/ibis/backends/tests/test_numeric.py b/ibis/backends/tests/test_numeric.py index 8afefc483447..57f30e3a3bcd 100644 --- a/ibis/backends/tests/test_numeric.py +++ b/ibis/backends/tests/test_numeric.py @@ -209,7 +209,6 @@ def test_math_functions_literals(backend, con, alltypes, df, expr, expected): lambda t: (-t.double_col).abs(), lambda t: (-t.double_col).abs(), id='abs-neg', - marks=pytest.mark.notimpl(["datafusion"]), ), param( lambda t: t.double_col.abs(),