Skip to content

Commit

Permalink
feat(datafusion): implement negate
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud committed May 18, 2022
1 parent a2ea283 commit 69dd64d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 10 additions & 0 deletions ibis/backends/datafusion/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
1 change: 0 additions & 1 deletion ibis/backends/tests/test_numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 69dd64d

Please sign in to comment.