scverse / spatialdata

An open and interoperable data framework for spatial omics data
https://spatialdata.scverse.org/
BSD 3-Clause "New" or "Revised" License
174 stars 34 forks source link

`get_extent()` does not recognizes `SpatialData` in the single dispatch pattern in specific cases #500

Closed LucaMarconato closed 1 month ago

LucaMarconato commented 1 month ago

Strange bug. Running the 00_xenium_and_visium.ipynb notebook, at the end of the notebook the get_extent() function does not recognize SpatialData for xe_rep1_roi_sdata. If we save the object and reload it, it works.

sd.get_extent(xe_rep1_roi_sdata)

gives

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[81], line 1
----> 1 sd.get_extent(xe_rep1_roi_sdata)

File ~/miniconda3/envs/ome/lib/python3.10/functools.py:889, in singledispatch.<locals>.wrapper(*args, **kw)
    885 if not args:
    886     raise TypeError(f'{funcname} requires at least '
    887                     '1 positional argument')
--> 889 return dispatch(args[0].__class__)(*args, **kw)

File ~/embl/projects/basel/spatialdata/src/spatialdata/_core/data_extent.py:174, in get_extent(e, coordinate_system, exact, has_images, has_labels, has_points, has_shapes, elements)
    106 @singledispatch
    107 def get_extent(
    108     e: SpatialData | SpatialElement,
   (...)
    117     ] = None,
    118 ) -> BoundingBoxDescription:
    119     """
    120     Get the extent (bounding box) of a SpatialData object or a SpatialElement.
    121 
   (...)
    172     the box `[minx, miny, maxx, maxy] = [-0.707, 0, 0.707, 1.414]`.
    173     """
--> 174     raise ValueError(f"The object type {type(e)} is not supported.")

ValueError: The object type <class 'spatialdata._core.spatialdata.SpatialData'> is not supported.

but

sd.get_extent(sd.read_zarr(XE_REP1_ROI_PATH), coordinate_system="aligned", exact=False)

works as expected.

LucaMarconato commented 1 month ago

Maybe it is just a problem with autoreload, I will re-run the notebook and check this. Edit: the problem disappeared, I attribute it to autoreload and close this.