Skip to content

Commit c311876

Browse files
fix: Prevent invalid syntax for no-op .replace ops (#2112)
1 parent 10b2a38 commit c311876

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

bigframes/core/compile/ibis_compiler/scalar_op_registry.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,10 @@ def udf(*inputs):
11731173

11741174
@scalar_op_compiler.register_unary_op(ops.MapOp, pass_op=True)
11751175
def map_op_impl(x: ibis_types.Value, op: ops.MapOp):
1176+
# this should probably be handled by a rewriter
1177+
if len(op.mappings) == 0:
1178+
return x
1179+
11761180
case = ibis_api.case()
11771181
for mapping in op.mappings:
11781182
case = case.when(x == mapping[0], mapping[1])

bigframes/core/compile/sqlglot/expressions/generic_ops.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ def _(expr: TypedExpr) -> sge.Expression:
7878

7979
@register_unary_op(ops.MapOp, pass_op=True)
8080
def _(expr: TypedExpr, op: ops.MapOp) -> sge.Expression:
81+
if len(op.mappings) == 0:
82+
return expr.expr
8183
return sge.Case(
8284
this=expr.expr,
8385
ifs=[

tests/system/small/test_series.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,10 +733,12 @@ def test_series_replace_nans_with_pd_na(scalars_dfs):
733733
(
734734
({"Hello, World!": "Howdy, Planet!", "T": "R"},),
735735
({},),
736+
({0: "Hello, World!"},),
736737
),
737738
ids=[
738739
"non-empty",
739740
"empty",
741+
"off-type",
740742
],
741743
)
742744
def test_series_replace_dict(scalars_dfs, replacement_dict):

0 commit comments

Comments
 (0)