Skip to content

Commit 5495d6d

Browse files
krzysztof-kwittcpcloud
authored andcommitted
feat(bigquery): implement ops.Clip
1 parent 5757bb0 commit 5495d6d

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

ibis/backends/bigquery/registry.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,18 @@ def _capitalize(t, op):
512512
return f"CONCAT(UPPER(SUBSTR({t.translate(op.arg)}, 1, 1)), SUBSTR({t.translate(op.arg)}, 2))"
513513

514514

515+
def _clip(t, op):
516+
arg = t.translate(op.arg)
517+
518+
if (upper := op.upper) is not None:
519+
arg = f"LEAST({t.translate(upper)}, {arg})"
520+
521+
if (lower := op.lower) is not None:
522+
arg = f"GREATEST({t.translate(lower)}, {arg})"
523+
524+
return arg
525+
526+
515527
OPERATION_REGISTRY = {
516528
**operation_registry,
517529
# Literal
@@ -533,6 +545,7 @@ def _capitalize(t, op):
533545
ops.Floor: compiles_floor,
534546
ops.Modulus: fixed_arity("MOD", 2),
535547
ops.Sign: unary("SIGN"),
548+
ops.Clip: _clip,
536549
# Temporal functions
537550
ops.Date: unary("DATE"),
538551
ops.DateFromYMD: fixed_arity("DATE", 3),

ibis/backends/tests/test_numeric.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ def test_random(con):
583583
),
584584
],
585585
)
586-
@pytest.mark.notimpl(["bigquery", "datafusion", "impala"])
586+
@pytest.mark.notimpl(["datafusion", "impala"])
587587
def test_clip(alltypes, df, ibis_func, pandas_func):
588588
result = ibis_func(alltypes.int_col).execute()
589589
expected = pandas_func(df.int_col).astype(result.dtype)

0 commit comments

Comments
 (0)