Skip to content

More informative error when subsetting results in no observations retained in Visium HD #1096

@matt-sd-watson

Description

@matt-sd-watson

When filtering bin spots in Visium HD, when using a sufficiently large expression filter:

mask = (sdata.tables[table].X > 0).sum(axis=1).A1 >= 500

The resulting table, if filtered using the mask, would contain no observations.

However, the error provided does not indicate this, and instead suggests a different type of data mismatch:

schema = get_model(value)
  File "/home/admin/.local/lib/python3.10/site-packages/spatialdata/models/models.py", line 1195, in get_model
    return _validate_and_return(TableModel, e)
  File "/home/admin/.local/lib/python3.10/site-packages/spatialdata/models/models.py", line 1178, in _validate_and_return
    schema().validate(e)
  File "/home/admin/.local/lib/python3.10/site-packages/spatialdata/models/models.py", line 1056, in validate
    self._validate_table_annotation_metadata(data)
  File "/home/admin/.local/lib/python3.10/site-packages/spatialdata/models/models.py", line 1034, in _validate_table_annotation_metadata
    raise ValueError(f"Regions in the AnnData object and `{attr[self.REGION_KEY_KEY]}` do not match.")
ValueError: Regions in the AnnData object and `region` do not match.

It may be useful to first have a check that the relevant table is non-empty before throwing this ValueError, as it suggested to be that a metadata column was corrupted or removed during processing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions