scverse / napari-spatialdata

Interactive visualization of spatial omics data
https://spatialdata.scverse.org/projects/napari/en/latest/
BSD 3-Clause "New" or "Revised" License
35 stars 14 forks source link

Error when filtering on multiple tables #244

Open berombau opened 2 months ago

berombau commented 2 months ago

Filtering does not work if an extra table is present not related to an element (which is a use case to save analysis results).

# napari_spatialdata/utils/_utils.py:361
for element_type, element_name, _ in sdata.filter_by_coordinate_system(coordinate_system_name)._gen_elements()

which calls:

# spatialdata/_core/spatialdata.py:737
table = _filter_table_by_element_names(table, element_names) # table is None and has no len
if len(table) != 0:
# TypeError: object of type 'NoneType' has no len()

To reproduce:

import spatialdata as sd
import anndata as ad
from spatialdata.datasets import blobs

sdata = blobs()
sdata.tables['table2'] = sd.models.TableModel.parse(ad.AnnData((10, 10)))
sdata.write('test.zarr')
# Open in napari-spatialdata, click on coordinate-system global, get error
melonora commented 1 month ago

@berombau thanks for reporting, I will have a look