Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[python/c++] Add SOMAGroup::is_relative and use in pytest unit tests #3166

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apis/python/src/tiledbsoma/soma_group.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ void load_soma_group(py::module& m) {
[](SOMAGroup& group) -> bool { return not group.is_open(); })
.def_property_readonly("uri", &SOMAGroup::uri)
.def("context", &SOMAGroup::ctx)
.def("is_relative", &SOMAGroup::is_relative)
.def("has", &SOMAGroup::has)
.def(
"add",
Expand Down
55 changes: 24 additions & 31 deletions apis/python/tests/test_basic_anndata_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,37 +353,30 @@ def test_ingest_relative(conftest_pbmc3k_h5ad_path, use_relative_uri):
if use_relative_uri is None:
expected_relative = True # since local disk

exp = tiledbsoma.open(output_path)
with tiledb.Group(exp.uri) as G:
assert G.is_relative("obs") == expected_relative
assert G.is_relative("ms") == expected_relative

with tiledb.Group(exp.ms.uri) as G:
assert G.is_relative("RNA") == expected_relative
with tiledb.Group(exp.ms["RNA"].uri) as G:
assert G.is_relative("var") == expected_relative
assert G.is_relative("X") == expected_relative
with tiledb.Group(exp.ms["RNA"].X.uri) as G:
assert G.is_relative("data") == expected_relative

for collection_name in [
"obsm",
"obsp",
"varm",
]: # conftest_h5ad_file_extended has no varp
with tiledb.Group(exp.ms["RNA"][collection_name].uri) as G:
for member in G:
assert G.is_relative(member.name) == expected_relative

with tiledb.Group(exp.ms.uri) as G:
assert G.is_relative("raw") == expected_relative
with tiledb.Group(exp.ms["raw"].uri) as G:
assert G.is_relative("var") == expected_relative
assert G.is_relative("X") == expected_relative
with tiledb.Group(exp.ms["raw"].X.uri) as G:
assert G.is_relative("data") == expected_relative

exp.close()
with tiledbsoma.Experiment.open(output_path) as G:
assert G._handle._handle.is_relative("obs") == expected_relative
assert G._handle._handle.is_relative("ms") == expected_relative

assert G.ms._handle._handle.is_relative("RNA") == expected_relative
assert G.ms["RNA"]._handle._handle.is_relative("var") == expected_relative
assert G.ms["RNA"]._handle._handle.is_relative("X") == expected_relative
assert G.ms["RNA"].X._handle._handle.is_relative("data") == expected_relative

for collection_name in [
"obsm",
"obsp",
"varm",
]: # conftest_h5ad_file_extended has no varp
for member in G.ms["RNA"][collection_name]:
assert (
G.ms["RNA"][collection_name]._handle._handle.is_relative(member)
== expected_relative
)

assert G.ms._handle._handle.is_relative("raw") == expected_relative
assert G.ms["raw"]._handle._handle.is_relative("var") == expected_relative
assert G.ms["raw"]._handle._handle.is_relative("X") == expected_relative
assert G.ms["raw"].X._handle._handle.is_relative("data") == expected_relative


@pytest.mark.parametrize("ingest_uns_keys", [["louvain_colors"], None])
Expand Down
9 changes: 9 additions & 0 deletions libtiledbsoma/src/soma/soma_group.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,15 @@ class SOMAGroup : public SOMAObject {
*/
std::shared_ptr<SOMAContext> ctx();

/**
* Check if a named member is relative
*
* @param name of member to retrieve associated relative indicator.
*/
bool is_relative(std::string name) const {
return group_->is_relative(name);
}

/**
* Get a member from the SOMAGroup given the index.
*
Expand Down
Loading