napari-spatialdata icon indicating copy to clipboard operation
napari-spatialdata copied to clipboard

Error when filtering on multiple tables

Open berombau opened this issue 1 year ago • 1 comments

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

berombau avatar May 23 '24 16:05 berombau

@berombau thanks for reporting, I will have a look

melonora avatar May 24 '24 05:05 melonora