Skip to content

Commit af76f56

Browse files
authored
tests: add engine tests for casting to json (#2070)
* tests: add engine tests for casting to json * remove test_engines_astype_struct_to_json for internal discussions 444196993
1 parent 6bd6738 commit af76f56

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tests/system/small/engines/test_generic_ops.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,29 @@ def test_engines_astype_from_json(scalars_array_value: array_value.ArrayValue, e
275275
assert_equivalence_execution(arr.node, REFERENCE_ENGINE, engine)
276276

277277

278+
@pytest.mark.parametrize("engine", ["polars", "bq"], indirect=True)
279+
def test_engines_astype_to_json(scalars_array_value: array_value.ArrayValue, engine):
280+
exprs = [
281+
ops.AsTypeOp(to_type=bigframes.dtypes.JSON_DTYPE).as_expr(
282+
expression.deref("int64_col")
283+
),
284+
ops.AsTypeOp(to_type=bigframes.dtypes.JSON_DTYPE).as_expr(
285+
# Use a const since float to json has precision issues
286+
expression.const(5.2, bigframes.dtypes.FLOAT_DTYPE)
287+
),
288+
ops.AsTypeOp(to_type=bigframes.dtypes.JSON_DTYPE).as_expr(
289+
expression.deref("bool_col")
290+
),
291+
ops.AsTypeOp(to_type=bigframes.dtypes.JSON_DTYPE).as_expr(
292+
# Use a const since "str_col" has special chars.
293+
expression.const('"hello world"', bigframes.dtypes.STRING_DTYPE)
294+
),
295+
]
296+
arr, _ = scalars_array_value.compute_values(exprs)
297+
298+
assert_equivalence_execution(arr.node, REFERENCE_ENGINE, engine)
299+
300+
278301
@pytest.mark.parametrize("engine", ["polars", "bq"], indirect=True)
279302
def test_engines_astype_timedelta(scalars_array_value: array_value.ArrayValue, engine):
280303
arr = apply_op(

0 commit comments

Comments
 (0)