Skip to content

Commit

Permalink
[python] Make ExperimentAxisQuery inherit somacore, restore its `…
Browse files Browse the repository at this point in the history
….close` (#3493)

* make EAQ inherit somacore, restore EAQ.close

* restore `test_query_cleanup` sans threadpool checks

* Update apis/python/src/tiledbsoma/_query.py

Co-authored-by: John Kerl <[email protected]>

---------

Co-authored-by: John Kerl <[email protected]>
  • Loading branch information
2 people authored and github-actions[bot] committed Dec 20, 2024
1 parent c124c45 commit 0d2648d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
7 changes: 5 additions & 2 deletions apis/python/src/tiledbsoma/_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def to_anndata(self) -> AnnData:
)


class ExperimentAxisQuery:
class ExperimentAxisQuery(query.ExperimentAxisQuery):
"""Axis-based query against a SOMA Experiment.
ExperimentAxisQuery allows easy selection and extraction of data from a
Expand Down Expand Up @@ -567,7 +567,10 @@ def to_spatialdata( # type: ignore[no-untyped-def]

return sdata

# Context management
# Context management.
# Currently a no-op, but, part of public API so we retain it.
def close(self) -> None:
pass

def __enter__(self) -> Self:
return self
Expand Down
20 changes: 20 additions & 0 deletions apis/python/tests/test_experiment_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,26 @@ def test_error_corners(soma_experiment: Experiment):
next(query.varp(lyr_name))


@pytest.mark.parametrize("n_obs,n_vars", [(1001, 99)])
def test_query_cleanup(soma_experiment: soma.Experiment):
"""
Verify soma.Experiment.query works as context manager and stand-alone,
and that it cleans up correctly.
"""
from contextlib import closing

context = SOMATileDBContext()
soma_experiment = get_soma_experiment_with_context(soma_experiment, context)

with soma_experiment.axis_query("RNA") as query:
assert query.n_obs == 1001
assert query.n_vars == 99
assert query.to_anndata("raw") is not None

with closing(soma_experiment.axis_query("RNA")) as query:
assert query.to_anndata("raw") is not None


@pytest.mark.parametrize(
"n_obs,n_vars,obsp_layer_names,varp_layer_names,obsm_layer_names,varm_layer_names",
[(1001, 99, ["foo"], ["bar"], ["baz"], ["quux"])],
Expand Down

0 comments on commit 0d2648d

Please sign in to comment.