From 6a12ef2911ad2b8c5d8167936e234f8dd532d3c2 Mon Sep 17 00:00:00 2001 From: Vivian Nguyen Date: Thu, 11 Jan 2024 10:51:36 -0600 Subject: [PATCH] Rebase and correct query condition code --- apis/python/src/tiledbsoma/_query_condition.py | 14 +++++--------- libtiledbsoma/test/test_query_condition.py | 11 ++++------- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/apis/python/src/tiledbsoma/_query_condition.py b/apis/python/src/tiledbsoma/_query_condition.py index efe49b974d..4644789396 100644 --- a/apis/python/src/tiledbsoma/_query_condition.py +++ b/apis/python/src/tiledbsoma/_query_condition.py @@ -134,8 +134,11 @@ def init_query_condition( schema: pa.Schema, query_attrs: Optional[List[str]], ): - qctree = QueryConditionTree(schema, query_attrs) - self.c_obj = qctree.visit(self.tree.body) + try: + qctree = QueryConditionTree(schema, query_attrs) + self.c_obj = qctree.visit(self.tree.body) + except Exception as pex: + raise SOMAError(pex) if not isinstance(self.c_obj, clib.PyQueryCondition): raise SOMAError( @@ -228,13 +231,6 @@ def visit_Compare(self, node: ast.Compare) -> clib.PyQueryCondition: raise SOMAError( "At least one value must be provided to the set membership" ) - - if self.schema.has_attr(variable): - enum_label = self.schema.attr(variable).enum_label - if enum_label is not None: - dt = self.enum_to_dtype[enum_label] - else: - dt = self.schema.attr(variable).dtype dt = self.schema.field(variable).type if pa.types.is_dictionary(dt): diff --git a/libtiledbsoma/test/test_query_condition.py b/libtiledbsoma/test/test_query_condition.py index dfcc0c6df4..3f2d21075d 100644 --- a/libtiledbsoma/test/test_query_condition.py +++ b/libtiledbsoma/test/test_query_condition.py @@ -218,19 +218,16 @@ def test_parsing_error_conditions(malformed_condition): def test_eval_error_conditions(malformed_condition): """Conditions which should not evaluate (but WILL parse)""" uri = os.path.join(SOMA_URI, "obs") - + schema = tiledb_schema_to_arrow(tiledb.open(uri).schema, uri, tiledb.default_ctx()) + qc = QueryCondition(malformed_condition) + with pytest.raises(SOMAError): - qc = QueryCondition(malformed_condition) - schema = tiledb.open(uri).schema sr = clib.SOMAArray(uri) sr.set_condition(qc, schema) - sr.read_next() with pytest.raises(SOMAError): - qc = QueryCondition(malformed_condition) - schema = tiledb.open(uri).schema # test function directly for codecov - qc.init_query_condition(schema, {}, []) + qc.init_query_condition(schema, []) if __name__ == "__main__":