diff --git a/apis/python/src/tiledbsoma/io/_registration/ambient_label_mappings.py b/apis/python/src/tiledbsoma/io/_registration/ambient_label_mappings.py index 150dfaff7f..e12d971891 100644 --- a/apis/python/src/tiledbsoma/io/_registration/ambient_label_mappings.py +++ b/apis/python/src/tiledbsoma/io/_registration/ambient_label_mappings.py @@ -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: @@ -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, diff --git a/apis/python/tests/test_registration_mappings.py b/apis/python/tests/test_registration_mappings.py index 1419e52477..0592a2abfd 100644 --- a/apis/python/tests/test_registration_mappings.py +++ b/apis/python/tests/test_registration_mappings.py @@ -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(