Skip to content

Commit 3c7425e

Browse files
committed
fix tests, improve exception, add docstring
1 parent 9d85686 commit 3c7425e

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

src/spatialdata_io/readers/visium_hd.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -672,19 +672,40 @@ def _decompose_projective_matrix(
672672

673673

674674
def _get_filename_prefix(path: Path, dataset_id: str | None) -> tuple[str, str]:
675+
"""Determine the filename prefix and dataset ID for Visium HD files.
676+
677+
The returned ``filename_prefix`` is used to locate files on disk (e.g., ``{prefix}feature_slice.h5``),
678+
while ``dataset_id`` is used to name elements in the ``SpatialData`` object.
679+
680+
Parameters
681+
----------
682+
path
683+
Path to the Visium HD output directory.
684+
dataset_id
685+
Optional identifier for naming elements. If ``None``, inferred from prefixed files.
686+
687+
Returns
688+
-------
689+
A tuple of ``(filename_prefix, dataset_id)``.
690+
691+
Raises
692+
------
693+
RuntimeError
694+
If the feature slice file cannot be located.
695+
"""
696+
if (path / VisiumHDKeys.FEATURE_SLICE_FILE.value).exists():
697+
return "", dataset_id if dataset_id is not None else ""
698+
675699
if dataset_id is None:
676-
if (path / VisiumHDKeys.FEATURE_SLICE_FILE.value).exists():
677-
return "", ""
678700
dataset_id = _infer_dataset_id(path)
679701

680702
if (path / f"{dataset_id}_{VisiumHDKeys.FEATURE_SLICE_FILE.value}").exists():
681703
return f"{dataset_id}_", dataset_id
682704

683-
assert (path / VisiumHDKeys.FEATURE_SLICE_FILE.value).exists(), (
684-
f"Cannot locate the feature slice file, please ensure the file is present in the {path} directory and/or adjust"
685-
"the `dataset_id` parameter"
705+
raise RuntimeError(
706+
f"Cannot locate the feature slice file, please ensure the file is present in the {path} directory and/or "
707+
"adjust the `dataset_id` parameter"
686708
)
687-
return "", ""
688709

689710

690711
def _parse_metadata(path: Path, filename_prefix: str) -> tuple[dict[str, Any], dict[str, Any]]:

0 commit comments

Comments
 (0)