Skip to content

Commit 1c9b898

Browse files
authored
Merge pull request #269 from VictoriaAdjeiQC/predicates_validation
Further validation for non-scalar values inside `check_predicates`
2 parents 2d049b5 + 605c4fa commit 1c9b898

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

CHANGES.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
Changelog
33
=========
44

5+
Plateau 4.6.2 (2025-08-XX)
6+
==========================
7+
8+
* Add further validation for predicates to raise errors if operators are misused with non-scalar values
9+
10+
511
Plateau 4.6.1 (2025-08-13)
612
==========================
713

plateau/serialization/_generic.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,19 @@ def check_predicates(predicates: PredicatesType) -> None:
203203
):
204204
raise ValueError(
205205
f"Invalid predicates: Clause {clause_idx} in conjunction {conjunction_idx} "
206-
f"with null value and operator {op}. Only operators supporting null values "
206+
f"with null value and operator '{op}'. Only operators supporting null values "
207207
"are '==', '!=', 'in' and 'is distinct from'."
208208
)
209+
if op == "in" and pd.api.types.is_scalar(val):
210+
raise ValueError(
211+
f"Invalid predicates in clause {clause_idx} in conjunction {conjunction_idx} "
212+
f"with operator '{op}' must be used with a tuple or list, got {type(val)} instead."
213+
)
214+
if op != "in" and is_list_like(val):
215+
raise ValueError(
216+
f"Invalid predicates in clause {clause_idx} in conjunction {conjunction_idx} "
217+
f"with operator '{op}' must be used with a scalar type, got {type(val)} instead."
218+
)
209219

210220

211221
def filter_predicates_by_column(

tests/io_components/test_read.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,19 @@ def test_dispatch_metapartitions(dataset, store_session):
2525

2626
@pytest.mark.parametrize(
2727
"predicates,error_msg",
28-
[([], "Empty predicates"), ([[]], "Invalid predicates: Conjunction 0 is empty")],
28+
[
29+
([], "Empty predicates"),
30+
([[]], "Invalid predicates: Conjunction 0 is empty"),
31+
(
32+
[[("mycol", "in", None)]],
33+
"Invalid predicates: Clause 0 in conjunction 0 with null value and operator 'in'.",
34+
),
35+
(
36+
[[("mycol", "in", "scalar")]],
37+
"operator 'in' must be used with a tuple or list",
38+
),
39+
([[("mycol", "<", [17, 12])]], "operator '<' must be used with a scalar type"),
40+
],
2941
)
3042
def test_dispatch_metapartition_undefined_behaviour(
3143
dataset, store_session, predicates, error_msg

0 commit comments

Comments
 (0)