Skip to content

Commit a4cf227

Browse files
committed
refactor: fix test_isin tests
1 parent b478b0c commit a4cf227

File tree

3 files changed

+37
-22
lines changed

3 files changed

+37
-22
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,23 @@
3131
@register_unary_op(ops.IsInOp, pass_op=True)
3232
def _(expr: TypedExpr, op: ops.IsInOp) -> sge.Expression:
3333
values = []
34-
is_numeric_expr = dtypes.is_numeric(expr.dtype)
34+
is_numeric_expr = dtypes.is_numeric(expr.dtype, include_bool=False)
3535
for value in op.values:
36-
if value is None:
36+
if _is_null(value):
3737
continue
3838
dtype = dtypes.bigframes_type(type(value))
39-
if expr.dtype == dtype or is_numeric_expr and dtypes.is_numeric(dtype):
39+
if (
40+
expr.dtype == dtype
41+
or is_numeric_expr
42+
and dtypes.is_numeric(dtype, include_bool=False)
43+
):
4044
values.append(sge.convert(value))
4145

4246
if op.match_nulls:
4347
contains_nulls = any(_is_null(value) for value in op.values)
4448
if contains_nulls:
49+
if len(values) == 0:
50+
return sge.Is(this=expr.expr, expression=sge.Null())
4551
return sge.Is(this=expr.expr, expression=sge.Null()) | sge.In(
4652
this=expr.expr, expressions=values
4753
)
Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,35 @@
11
WITH `bfcte_0` AS (
22
SELECT
3+
`bool_col`,
34
`float64_col`,
45
`int64_col`
56
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
67
), `bfcte_1` AS (
78
SELECT
89
*,
9-
COALESCE(`int64_col` IN (1, 2, 3), FALSE) AS `bfcol_2`,
10-
(
11-
`int64_col` IS NULL
12-
) OR `int64_col` IN (123456) AS `bfcol_3`,
13-
COALESCE(`int64_col` IN (1.0, 2.0, 3.0), FALSE) AS `bfcol_4`,
14-
FALSE AS `bfcol_5`,
15-
COALESCE(`int64_col` IN (2.5, 3), FALSE) AS `bfcol_6`,
10+
COALESCE(`bool_col` IN (TRUE, FALSE), FALSE) AS `bfcol_3`,
11+
COALESCE(`int64_col` IN (1, 2, 3), FALSE) AS `bfcol_4`,
12+
`int64_col` IS NULL AS `bfcol_5`,
13+
COALESCE(`int64_col` IN (1.0, 2.0, 3.0), FALSE) AS `bfcol_6`,
1614
FALSE AS `bfcol_7`,
17-
COALESCE(`int64_col` IN (123456), FALSE) AS `bfcol_8`,
15+
COALESCE(`int64_col` IN (2.5, 3), FALSE) AS `bfcol_8`,
16+
FALSE AS `bfcol_9`,
17+
FALSE AS `bfcol_10`,
18+
COALESCE(`int64_col` IN (123456), FALSE) AS `bfcol_11`,
1819
(
1920
`float64_col` IS NULL
20-
) OR `float64_col` IN (1, 2, 3) AS `bfcol_9`
21+
) OR `float64_col` IN (1, 2, 3) AS `bfcol_12`
2122
FROM `bfcte_0`
2223
)
2324
SELECT
24-
`bfcol_2` AS `ints`,
25-
`bfcol_3` AS `ints_w_null`,
26-
`bfcol_4` AS `floats`,
27-
`bfcol_5` AS `strings`,
28-
`bfcol_6` AS `mixed`,
29-
`bfcol_7` AS `empty`,
30-
`bfcol_8` AS `ints_wo_match_nulls`,
31-
`bfcol_9` AS `float_in_ints`
25+
`bfcol_3` AS `bools`,
26+
`bfcol_4` AS `ints`,
27+
`bfcol_5` AS `ints_w_null`,
28+
`bfcol_6` AS `floats`,
29+
`bfcol_7` AS `strings`,
30+
`bfcol_8` AS `mixed`,
31+
`bfcol_9` AS `empty`,
32+
`bfcol_10` AS `empty_wo_match_nulls`,
33+
`bfcol_11` AS `ints_wo_match_nulls`,
34+
`bfcol_12` AS `float_in_ints`
3235
FROM `bfcte_1`

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import pandas as pd
1516
import pytest
1617

1718
from bigframes import operations as ops
@@ -22,18 +23,23 @@
2223

2324

2425
def test_is_in(scalar_types_df: bpd.DataFrame, snapshot):
26+
bool_col = "bool_col"
2527
int_col = "int64_col"
2628
float_col = "float64_col"
27-
bf_df = scalar_types_df[[int_col, float_col]]
29+
bf_df = scalar_types_df[[bool_col, int_col, float_col]]
2830
ops_map = {
31+
"bools": ops.IsInOp(values=(True, False)).as_expr(bool_col),
2932
"ints": ops.IsInOp(values=(1, 2, 3)).as_expr(int_col),
30-
"ints_w_null": ops.IsInOp(values=(None, 123456)).as_expr(int_col),
33+
"ints_w_null": ops.IsInOp(values=(None, pd.NA)).as_expr(int_col),
3134
"floats": ops.IsInOp(values=(1.0, 2.0, 3.0), match_nulls=False).as_expr(
3235
int_col
3336
),
3437
"strings": ops.IsInOp(values=("1.0", "2.0")).as_expr(int_col),
3538
"mixed": ops.IsInOp(values=("1.0", 2.5, 3)).as_expr(int_col),
3639
"empty": ops.IsInOp(values=()).as_expr(int_col),
40+
"empty_wo_match_nulls": ops.IsInOp(values=(), match_nulls=False).as_expr(
41+
int_col
42+
),
3743
"ints_wo_match_nulls": ops.IsInOp(
3844
values=(None, 123456), match_nulls=False
3945
).as_expr(int_col),

0 commit comments

Comments
 (0)