Skip to content

Commit

Permalink
Rebase and correct query condition code
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenv committed Jan 11, 2024
1 parent 9647fbe commit 6a12ef2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
14 changes: 5 additions & 9 deletions apis/python/src/tiledbsoma/_query_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check warning on line 141 in apis/python/src/tiledbsoma/_query_condition.py

View check run for this annotation

Codecov / codecov/patch

apis/python/src/tiledbsoma/_query_condition.py#L140-L141

Added lines #L140 - L141 were not covered by tests

if not isinstance(self.c_obj, clib.PyQueryCondition):
raise SOMAError(

Check warning on line 144 in apis/python/src/tiledbsoma/_query_condition.py

View check run for this annotation

Codecov / codecov/patch

apis/python/src/tiledbsoma/_query_condition.py#L144

Added line #L144 was not covered by tests
Expand Down Expand Up @@ -228,13 +231,6 @@ def visit_Compare(self, node: ast.Compare) -> clib.PyQueryCondition:
raise SOMAError(

Check warning on line 231 in apis/python/src/tiledbsoma/_query_condition.py

View check run for this annotation

Codecov / codecov/patch

apis/python/src/tiledbsoma/_query_condition.py#L231

Added line #L231 was not covered by tests
"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):
Expand Down
11 changes: 4 additions & 7 deletions libtiledbsoma/test/test_query_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down

0 comments on commit 6a12ef2

Please sign in to comment.