From e4edcf0195a8404b9e9787218645022fb05e5f44 Mon Sep 17 00:00:00 2001 From: Vivian Nguyen Date: Mon, 4 Dec 2023 12:04:24 -0600 Subject: [PATCH] Error out if query condition given empty set --- tiledb/query_condition.py | 3 +++ tiledb/tests/test_query_condition.py | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/tiledb/query_condition.py b/tiledb/query_condition.py index b6c1a90ce6..7f910199a7 100644 --- a/tiledb/query_condition.py +++ b/tiledb/query_condition.py @@ -222,6 +222,9 @@ def visit_Compare(self, node: Type[ast.Compare]) -> qc.PyQueryCondition: variable = node.left.id values = [self.get_value_from_node(val) for val in self.visit(rhs)] + if len(values) == 0: + raise TileDBError("At least one value must be provided to " + "the set membership") if self.array.schema.has_attr(variable): enum_label = self.array.attr(variable).enum_label diff --git a/tiledb/tests/test_query_condition.py b/tiledb/tests/test_query_condition.py index 649da89c7d..9f53202b17 100644 --- a/tiledb/tests/test_query_condition.py +++ b/tiledb/tests/test_query_condition.py @@ -550,6 +550,10 @@ def test_in_operator_sparse(self): result = A.query(cond="U not in [5, 6, 7]")[:] for val in result["U"]: assert val not in [5, 6, 7] + + with pytest.raises(tiledb.TileDBError) as exc_info: + A.query(cond="U not in []")[:] + assert "At least one value must be provided to the set membership" in str(exc_info.value) def test_in_operator_dense(self): with tiledb.open(self.create_input_array_UIDSA(sparse=False)) as A: @@ -581,6 +585,10 @@ def test_in_operator_dense(self): result = A.query(cond="U not in [5, 6, 7]")[:] for val in self.filter_dense(result["U"], U_mask): assert val not in [5, 6, 7] + + with pytest.raises(tiledb.TileDBError) as exc_info: + A.query(cond="U not in []")[:] + assert "At least one value must be provided to the set membership" in str(exc_info.value) @pytest.mark.skipif(not has_pandas(), reason="pandas not installed") def test_dense_datetime(self):