From 483e702c4f83331b8f9d7a116a20e88d81a374f3 Mon Sep 17 00:00:00 2001 From: Vivian Nguyen Date: Tue, 27 Sep 2022 11:33:03 -0500 Subject: [PATCH 1/4] Do Not Require Attribute in Query Condition To Be Passed to Query --- tiledb/core.cc | 2 +- tiledb/query_condition.py | 11 +++++++---- tiledb/tests/test_query_condition.py | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/tiledb/core.cc b/tiledb/core.cc index 75cb656973..b5042dbc44 100644 --- a/tiledb/core.cc +++ b/tiledb/core.cc @@ -711,7 +711,7 @@ class PyQuery { py::object init_pyqc = attr_cond.attr("init_query_condition"); try { - init_pyqc(pyschema_, attrs_); + attrs_ = init_pyqc(pyschema_, attrs_).cast>(); } catch (tiledb::TileDBError &e) { TPY_ERROR_LOC(e.what()); } catch (py::error_already_set &e) { diff --git a/tiledb/query_condition.py b/tiledb/query_condition.py index 3bed758986..2ddd392a57 100644 --- a/tiledb/query_condition.py +++ b/tiledb/query_condition.py @@ -135,6 +135,8 @@ def init_query_condition(self, schema: tiledb.ArraySchema, query_attrs: List[str "be made up of one or more Boolean expressions." ) + return query_attrs + @dataclass class QueryConditionTree(ast.NodeVisitor): @@ -318,10 +320,11 @@ def get_att_from_node(self, node: QueryConditionNodeElem) -> Any: raise tiledb.TileDBError(f"Attribute `{att}` not found in schema.") if att not in self.query_attrs: - raise tiledb.TileDBError( - f"Attribute `{att}` given to filter in query's `attr_cond` " - "arg but not found in `attr` arg." - ) + self.query_attrs.append(att) + # raise tiledb.TileDBError( + # f"Attribute `{att}` given to filter in query's `attr_cond` " + # "arg but not found in `attr` arg." + # ) return att diff --git a/tiledb/tests/test_query_condition.py b/tiledb/tests/test_query_condition.py index 93160df297..2d8d126d3c 100644 --- a/tiledb/tests/test_query_condition.py +++ b/tiledb/tests/test_query_condition.py @@ -1,6 +1,7 @@ import pytest import numpy as np +from numpy.testing import assert_array_equal import string import tiledb @@ -665,3 +666,17 @@ def test_array_with_bool_but_unused(self): qc = tiledb.QueryCondition("myint > 10") result = A.query(attr_cond=qc, attrs=["myint"])[:] assert all(result["myint"] > 10) + + def test_do_not_return_queried_attr(self): + with tiledb.open(self.create_input_array_UIDSA(sparse=True)) as A: + qc = tiledb.QueryCondition("U < 3") + + i_result = A.query(attr_cond=qc, attrs=["I", "U"])[:] + assert "I" in i_result.keys() + assert "U" in i_result.keys() + assert all(i_result["U"] < 5) + + u_result = A.query(attr_cond=qc, attrs=["I"])[:] + assert "I" in u_result.keys() + assert "U" not in u_result.keys() + assert_array_equal(i_result["I"], u_result["I"]) From 9a6b60eae5295bd71c9b81bcf13187e23bdd9952 Mon Sep 17 00:00:00 2001 From: Vivian Nguyen Date: Tue, 27 Sep 2022 11:37:50 -0500 Subject: [PATCH 2/4] Update HISTORY.md --- HISTORY.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/HISTORY.md b/HISTORY.md index c884aa07c0..ebfae62419 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,8 @@ +# In Progress + +## API Changes +* Attributes in query conditions no longer need to be passed to `Array.query`'s `attr` arg [#1333](https://github.com/TileDB-Inc/TileDB-Py/pull/1333) + # TileDB-Py 0.17.4 Release Notes ## TileDB Embedded updates: From af9d030504e8bc714e7d37d174b12c51d0fb508e Mon Sep 17 00:00:00 2001 From: Vivian Nguyen Date: Tue, 27 Sep 2022 11:46:43 -0500 Subject: [PATCH 3/4] Review Feedback: Remove Commented Out Items --- tiledb/query_condition.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tiledb/query_condition.py b/tiledb/query_condition.py index 2ddd392a57..76222aaf91 100644 --- a/tiledb/query_condition.py +++ b/tiledb/query_condition.py @@ -321,10 +321,6 @@ def get_att_from_node(self, node: QueryConditionNodeElem) -> Any: if att not in self.query_attrs: self.query_attrs.append(att) - # raise tiledb.TileDBError( - # f"Attribute `{att}` given to filter in query's `attr_cond` " - # "arg but not found in `attr` arg." - # ) return att From 81fcc3eaaff2756dea26976943dc06c00fca87a0 Mon Sep 17 00:00:00 2001 From: Vivian Nguyen Date: Tue, 27 Sep 2022 13:12:48 -0500 Subject: [PATCH 4/4] Remove Outdated Query Condition Tests --- tiledb/tests/test_query_condition.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/tiledb/tests/test_query_condition.py b/tiledb/tests/test_query_condition.py index 2d8d126d3c..bbf1a4bf17 100644 --- a/tiledb/tests/test_query_condition.py +++ b/tiledb/tests/test_query_condition.py @@ -307,10 +307,6 @@ def test_check_attrs_sparse(self): qc = tiledb.QueryCondition("U < 'one'") A.query(attr_cond=qc, attrs=["U"])[:] - with self.assertRaises(tiledb.TileDBError): - qc = tiledb.QueryCondition("U < 1") - A.query(attr_cond=qc, attrs=["D"])[:] - def test_check_attrs_dense(self): with tiledb.open(self.create_input_array_UIDSA(sparse=False)) as A: mask = A.attr("U").fill @@ -331,10 +327,6 @@ def test_check_attrs_dense(self): qc = tiledb.QueryCondition("U < 'one'") A.query(attr_cond=qc, attrs=["U"])[:] - with self.assertRaises(tiledb.TileDBError): - qc = tiledb.QueryCondition("U < 1") - A.query(attr_cond=qc, attrs=["D"])[:] - @pytest.mark.parametrize("sparse", [True, False]) def test_error_when_using_dim(self, sparse): with tiledb.open(self.create_input_array_UIDSA(sparse)) as A: