Skip to content

Commit

Permalink
chore: fix clip
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud committed Sep 26, 2023
1 parent a2b848d commit ff5855e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
12 changes: 10 additions & 2 deletions ibis/backends/duckdb/compiler/values.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,18 @@ def _generic_log(op, **kw):
def _clip(op, **kw):
arg = translate_val(op.arg, **kw)
if (upper := op.upper) is not None:
arg = sg.exp.Least.from_arg_list([translate_val(upper, **kw), arg])
arg = sg.exp.If(
this=arg.is_(NULL),
true=sg.exp.NULL,
false=sg.exp.Least.from_arg_list([translate_val(upper, **kw), arg]),
)

if (lower := op.lower) is not None:
arg = sg.exp.Greatest.from_arg_list([translate_val(lower, **kw), arg])
arg = sg.exp.If(
this=arg.is_(NULL),
true=sg.exp.NULL,
false=sg.exp.Greatest.from_arg_list([translate_val(lower, **kw), arg]),
)

return arg

Expand Down
3 changes: 2 additions & 1 deletion ibis/backends/tests/test_numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -1386,7 +1386,8 @@ def test_random(con):
@pytest.mark.notimpl(["datafusion"], raises=com.OperationNotDefinedError)
def test_clip(backend, alltypes, df, ibis_func, pandas_func):
result = ibis_func(alltypes.int_col).execute()
expected = pandas_func(df.int_col).astype(result.dtype)
raw_expected = pandas_func(df.int_col)
expected = raw_expected.astype(result.dtype)
# Names won't match in the PySpark backend since PySpark
# gives 'tmp' name when executing a Column
backend.assert_series_equal(result, expected, check_names=False)
Expand Down

0 comments on commit ff5855e

Please sign in to comment.