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] Enforce if-not-exists semantics for append/registration #2384

Merged
merged 2 commits into from
Apr 4, 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
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,10 @@ def _acquire_experiment_mappings(
) -> Self:
"""Acquires label-to-ID mappings from the baseline, already-written SOMA experiment."""

if experiment_uri is not None and tiledbsoma.Experiment.exists(experiment_uri):
if experiment_uri is not None:
if not tiledbsoma.Experiment.exists(experiment_uri):
raise ValueError("cannot find experiment at URI {experiment_uri}")

# Pre-check
with tiledbsoma.Experiment.open(experiment_uri, context=context) as exp:
if measurement_name not in exp.ms:
Expand Down Expand Up @@ -387,7 +390,10 @@ def from_anndata_appends_on_experiment(
context: Optional[SOMATileDBContext] = None,
) -> Self:
"""Extends registration data from the baseline, already-written SOMA
experiment to include multiple H5AD input files."""
experiment to include multiple H5AD input files. If ``experiment_uri``
is ``None`` then you will be computing registrations only for the input
``AnnData`` objects. If ``experiment_uri`` is not ``None`` then it is
an error if the experiment is not accessible."""

registration_data = cls._acquire_experiment_mappings(
experiment_uri,
Expand Down
17 changes: 17 additions & 0 deletions apis/python/tests/test_registration_mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -1164,6 +1164,23 @@ def test_ealm_expose():
assert tiledbsoma.io.ExperimentAmbientLabelMapping is not None


def test_append_registration_with_nonexistent_storage(tmp_path):
anndata1 = create_anndata_canned(1, "obs_id", "var_id")
anndata2 = create_anndata_canned(2, "obs_id", "var_id")
soma_uri = tmp_path.as_posix()

tiledbsoma.io.from_anndata(soma_uri, anndata1, measurement_name="RNA")

with pytest.raises(ValueError):
tiledbsoma.io.register_anndatas(
soma_uri + "-nonesuch",
[anndata2],
measurement_name="RNA",
obs_field_name="obs_id",
var_field_name="var_id",
)


@pytest.mark.parametrize("obs_field_name", ["obs_id", "cell_id"])
@pytest.mark.parametrize("var_field_name", ["var_id", "gene_id"])
@pytest.mark.parametrize(
Expand Down
Loading