From 42f8ce00137fd20c7092aac588539e3ef768031e Mon Sep 17 00:00:00 2001 From: Julia Dark <24235303+jp-dark@users.noreply.github.com> Date: Wed, 18 Dec 2024 13:10:20 -0500 Subject: [PATCH] [python] Add extra asserts for SpatialData tests (#3470) * Show spatialdata version * Add check in tests for export to SpatialData for query scene IDs --- apis/python/tests/test_experiment_query_spatial.py | 14 ++++++++++++++ scripts/show-versions.py | 13 +++++++++++++ 2 files changed, 27 insertions(+) diff --git a/apis/python/tests/test_experiment_query_spatial.py b/apis/python/tests/test_experiment_query_spatial.py index cd0ab982dd..14dc9cda3e 100644 --- a/apis/python/tests/test_experiment_query_spatial.py +++ b/apis/python/tests/test_experiment_query_spatial.py @@ -300,6 +300,13 @@ def test_spatial_experiment_query_obs_slice( assert query.n_obs == obs_slice.stop - obs_slice.start + 1 assert query.n_vars == 100 + # Check the expected scenes are included. + scene_ids = set(str(val) for val in query.obs_scene_ids()) + expected_scene_ids = set( + f"scene{index}" for index, val in enumerate(has_scene) if val + ) + assert scene_ids == expected_scene_ids + # Read to SpatialData. sdata = query.to_spatialdata("data") @@ -329,6 +336,13 @@ def test_spatial_experiment_query_var_slice( assert query.n_obs == 64 assert query.n_vars == var_slice.stop - var_slice.start + 1 + # Check the expected scenes are included. + scene_ids = set(str(val) for val in query.var_scene_ids()) + expected_scene_ids = set( + f"scene{index}" for index, val in enumerate(has_scene) if val + ) + assert scene_ids == expected_scene_ids + # Read to SpatialData. sdata = query.to_spatialdata("data", scene_presence_mode="var") diff --git a/scripts/show-versions.py b/scripts/show-versions.py index 448ffb85ce..2258afabdf 100755 --- a/scripts/show-versions.py +++ b/scripts/show-versions.py @@ -9,6 +9,15 @@ import scanpy as sc import scipy as sp +try: + import spatialdata as sd + + HAS_SPATIALDATA = True +except ImportError: + + HAS_SPATIALDATA = False + + import tiledbsoma print("tiledbsoma.__version__ ", tiledbsoma.__version__) @@ -19,5 +28,9 @@ print("pyarrow.__version__ (pa)", pa.__version__) print("scanpy.__version__ (sc)", sc.__version__) print("scipy.__version__ (sp)", sp.__version__) +if HAS_SPATIALDATA: + print("spatialdata.__version__ (sd)", sd.__version__) +else: + print("spatialdata not installed") v = sys.version_info print("python__version__ ", ".".join(map(str, (v.major, v.minor, v.micro))))