diff --git a/bigframes/core/compile/ibis_compiler/scalar_op_registry.py b/bigframes/core/compile/ibis_compiler/scalar_op_registry.py index e8a2b0b6ce..635ba516e4 100644 --- a/bigframes/core/compile/ibis_compiler/scalar_op_registry.py +++ b/bigframes/core/compile/ibis_compiler/scalar_op_registry.py @@ -1173,6 +1173,10 @@ def udf(*inputs): @scalar_op_compiler.register_unary_op(ops.MapOp, pass_op=True) def map_op_impl(x: ibis_types.Value, op: ops.MapOp): + # this should probably be handled by a rewriter + if len(op.mappings) == 0: + return x + case = ibis_api.case() for mapping in op.mappings: case = case.when(x == mapping[0], mapping[1]) diff --git a/bigframes/core/compile/sqlglot/expressions/generic_ops.py b/bigframes/core/compile/sqlglot/expressions/generic_ops.py index 8a792c0753..6a3825309c 100644 --- a/bigframes/core/compile/sqlglot/expressions/generic_ops.py +++ b/bigframes/core/compile/sqlglot/expressions/generic_ops.py @@ -78,6 +78,8 @@ def _(expr: TypedExpr) -> sge.Expression: @register_unary_op(ops.MapOp, pass_op=True) def _(expr: TypedExpr, op: ops.MapOp) -> sge.Expression: + if len(op.mappings) == 0: + return expr.expr return sge.Case( this=expr.expr, ifs=[ diff --git a/tests/system/small/test_series.py b/tests/system/small/test_series.py index d1a252f8dc..65b170df32 100644 --- a/tests/system/small/test_series.py +++ b/tests/system/small/test_series.py @@ -733,10 +733,12 @@ def test_series_replace_nans_with_pd_na(scalars_dfs): ( ({"Hello, World!": "Howdy, Planet!", "T": "R"},), ({},), + ({0: "Hello, World!"},), ), ids=[ "non-empty", "empty", + "off-type", ], ) def test_series_replace_dict(scalars_dfs, replacement_dict):