Skip to content

Commit a6af134

Browse files
committed
Revert "reuse the testing utils.py method"
This reverts commit 9fad51c.
1 parent 62d9d31 commit a6af134

File tree

7 files changed

+42
-17
lines changed

7 files changed

+42
-17
lines changed

bigframes/testing/utils.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -467,20 +467,21 @@ def _apply_unary_ops(
467467
return sql
468468

469469

470-
def _apply_nary_op(
470+
def _apply_binary_op(
471471
obj: bpd.DataFrame,
472-
op: Union[ops.BinaryOp, ops.NaryOp],
473-
*args: Union[str, ex.Expression],
472+
op: ops.BinaryOp,
473+
l_arg: str,
474+
r_arg: Union[str, ex.Expression],
474475
) -> str:
475-
"""Applies a nary op to the given DataFrame and return the SQL representing
476+
"""Applies a binary op to the given DataFrame and return the SQL representing
476477
the resulting DataFrame."""
477478
array_value = obj._block.expr
478-
op_expr = op.as_expr(*args)
479+
op_expr = op.as_expr(l_arg, r_arg)
479480
result, col_ids = array_value.compute_values([op_expr])
480481

481482
# Rename columns for deterministic golden SQL results.
482483
assert len(col_ids) == 1
483-
result = result.rename_columns({col_ids[0]: args[0]}).select_columns([args[0]])
484+
result = result.rename_columns({col_ids[0]: l_arg}).select_columns([l_arg])
484485

485486
sql = result.session._executor.to_sql(result, enable_cache=False)
486487
return sql

tests/unit/core/compile/sqlglot/expressions/snapshots/test_struct_ops/test_struct_op/out.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ WITH `bfcte_0` AS (
1717
FROM `bfcte_0`
1818
)
1919
SELECT
20-
`bfcol_4` AS `bool_col`
20+
`bfcol_4` AS `result_col`
2121
FROM `bfcte_1`

tests/unit/core/compile/sqlglot/expressions/test_comparison_ops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def test_is_in(scalar_types_df: bpd.DataFrame, snapshot):
4646

4747
def test_eq_null_match(scalar_types_df: bpd.DataFrame, snapshot):
4848
bf_df = scalar_types_df[["int64_col", "bool_col"]]
49-
sql = utils._apply_nary_op(bf_df, ops.eq_null_match_op, "int64_col", "bool_col")
49+
sql = utils._apply_binary_op(bf_df, ops.eq_null_match_op, "int64_col", "bool_col")
5050
snapshot.assert_match(sql, "out.sql")
5151

5252

tests/unit/core/compile/sqlglot/expressions/test_json_ops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def test_to_json_string(json_types_df: bpd.DataFrame, snapshot):
102102

103103
def test_json_set(json_types_df: bpd.DataFrame, snapshot):
104104
bf_df = json_types_df[["json_col"]]
105-
sql = utils._apply_nary_op(
105+
sql = utils._apply_binary_op(
106106
bf_df, ops.JSONSet(json_path="$.a"), "json_col", ex.const(100)
107107
)
108108

tests/unit/core/compile/sqlglot/expressions/test_numeric_ops.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def test_add_numeric(scalar_types_df: bpd.DataFrame, snapshot):
221221

222222
def test_add_string(scalar_types_df: bpd.DataFrame, snapshot):
223223
bf_df = scalar_types_df[["string_col"]]
224-
sql = utils._apply_nary_op(bf_df, ops.add_op, "string_col", ex.const("a"))
224+
sql = utils._apply_binary_op(bf_df, ops.add_op, "string_col", ex.const("a"))
225225

226226
snapshot.assert_match(sql, "out.sql")
227227

@@ -241,10 +241,10 @@ def test_add_timedelta(scalar_types_df: bpd.DataFrame, snapshot):
241241

242242
def test_add_unsupported_raises(scalar_types_df: bpd.DataFrame):
243243
with pytest.raises(TypeError):
244-
utils._apply_nary_op(scalar_types_df, ops.add_op, "timestamp_col", "date_col")
244+
utils._apply_binary_op(scalar_types_df, ops.add_op, "timestamp_col", "date_col")
245245

246246
with pytest.raises(TypeError):
247-
utils._apply_nary_op(scalar_types_df, ops.add_op, "int64_col", "string_col")
247+
utils._apply_binary_op(scalar_types_df, ops.add_op, "int64_col", "string_col")
248248

249249

250250
def test_div_numeric(scalar_types_df: bpd.DataFrame, snapshot):
@@ -361,7 +361,7 @@ def test_sub_timedelta(scalar_types_df: bpd.DataFrame, snapshot):
361361

362362
def test_sub_unsupported_raises(scalar_types_df: bpd.DataFrame):
363363
with pytest.raises(TypeError):
364-
utils._apply_nary_op(scalar_types_df, ops.sub_op, "string_col", "string_col")
364+
utils._apply_binary_op(scalar_types_df, ops.sub_op, "string_col", "string_col")
365365

366366
with pytest.raises(TypeError):
367-
utils._apply_nary_op(scalar_types_df, ops.sub_op, "int64_col", "string_col")
367+
utils._apply_binary_op(scalar_types_df, ops.sub_op, "int64_col", "string_col")

tests/unit/core/compile/sqlglot/expressions/test_string_ops.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,13 +308,13 @@ def test_zfill(scalar_types_df: bpd.DataFrame, snapshot):
308308

309309
def test_add_string(scalar_types_df: bpd.DataFrame, snapshot):
310310
bf_df = scalar_types_df[["string_col"]]
311-
sql = utils._apply_nary_op(bf_df, ops.add_op, "string_col", ex.const("a"))
311+
sql = utils._apply_binary_op(bf_df, ops.add_op, "string_col", ex.const("a"))
312312

313313
snapshot.assert_match(sql, "out.sql")
314314

315315

316316
def test_strconcat(scalar_types_df: bpd.DataFrame, snapshot):
317317
bf_df = scalar_types_df[["string_col"]]
318-
sql = utils._apply_nary_op(bf_df, ops.strconcat_op, "string_col", ex.const("a"))
318+
sql = utils._apply_binary_op(bf_df, ops.strconcat_op, "string_col", ex.const("a"))
319319

320320
snapshot.assert_match(sql, "out.sql")

tests/unit/core/compile/sqlglot/expressions/test_struct_ops.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,39 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import typing
16+
1517
import pytest
1618

1719
from bigframes import operations as ops
20+
from bigframes.core import expression as ex
1821
import bigframes.pandas as bpd
1922
from bigframes.testing import utils
2023

2124
pytest.importorskip("pytest_snapshot")
2225

2326

27+
def _apply_nary_op(
28+
obj: bpd.DataFrame,
29+
op: ops.NaryOp,
30+
*args: typing.Union[str, ex.Expression],
31+
) -> str:
32+
"""Applies a nary op to the given DataFrame and return the SQL representing
33+
the resulting DataFrame."""
34+
array_value = obj._block.expr
35+
op_expr = op.as_expr(*args)
36+
result, col_ids = array_value.compute_values([op_expr])
37+
38+
# Rename columns for deterministic golden SQL results.
39+
assert len(col_ids) == 1
40+
result = result.rename_columns({col_ids[0]: "result_col"}).select_columns(
41+
["result_col"]
42+
)
43+
44+
sql = result.session._executor.to_sql(result, enable_cache=False)
45+
return sql
46+
47+
2448
def test_struct_field(nested_structs_types_df: bpd.DataFrame, snapshot):
2549
col_name = "people"
2650
bf_df = nested_structs_types_df[[col_name]]
@@ -39,6 +63,6 @@ def test_struct_field(nested_structs_types_df: bpd.DataFrame, snapshot):
3963
def test_struct_op(scalar_types_df: bpd.DataFrame, snapshot):
4064
bf_df = scalar_types_df[["bool_col", "int64_col", "float64_col", "string_col"]]
4165
op = ops.StructOp(column_names=tuple(bf_df.columns.tolist()))
42-
sql = utils._apply_nary_op(bf_df, op, *bf_df.columns.tolist())
66+
sql = _apply_nary_op(bf_df, op, *bf_df.columns.tolist())
4367

4468
snapshot.assert_match(sql, "out.sql")

0 commit comments

Comments
 (0)