Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround for nan radii xenium #658

Merged
merged 1 commit into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/spatialdata/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,14 @@ def validate(cls, data: GeoDataFrame) -> None:
if np.any(radii <= 0):
raise ValueError("Radii of circles must be positive.")
if np.any(np.isnan(radii)) or np.any(np.isinf(radii)):
raise ValueError("Radii of circles must not be nan or inf.")
# using logger.warning instead of warnings.warn to avoid the warning to being silenced in some cases
# (e.g. PyCharm console)
logger.warning(
"Radii of circles must not be nan or inf (this warning will be turned into a ValueError in the "
"next code release). If you are seeing this warning after reading previously saved Xenium data, "
"please see https://github.com/scverse/spatialdata/discussions/657 for a solution. Otherwise, "
"please correct the radii of the circles before calling the parser function.",
)
if cls.TRANSFORM_KEY not in data.attrs:
raise ValueError(f":class:`geopandas.GeoDataFrame` does not contain `{TRANSFORM_KEY}`." + SUGGESTION)
if len(data) > 0:
Expand Down
16 changes: 10 additions & 6 deletions tests/models/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,16 @@ def test_shapes_model(self, model: ShapesModel, path: Path) -> None:
poly[ShapesModel.RADIUS_KEY].iloc[0] = 0
with pytest.raises(ValueError, match="Radii of circles must be positive."):
ShapesModel.validate(poly)
poly[ShapesModel.RADIUS_KEY].iloc[0] = np.nan
with pytest.raises(ValueError, match="Radii of circles must not be nan or inf."):
ShapesModel.validate(poly)
poly[ShapesModel.RADIUS_KEY].iloc[0] = np.inf
with pytest.raises(ValueError, match="Radii of circles must not be nan or inf."):
ShapesModel.validate(poly)

# tests to be restored when the validation is re-enabled (now it just raises a warning, that is tricky to
# capture)
# poly[ShapesModel.RADIUS_KEY].iloc[0] = np.nan
# with pytest.raises(ValueError, match="Radii of circles must not be nan or inf."):
# ShapesModel.validate(poly)
#
# poly[ShapesModel.RADIUS_KEY].iloc[0] = np.inf
# with pytest.raises(ValueError, match="Radii of circles must not be nan or inf."):
# ShapesModel.validate(poly)

@pytest.mark.parametrize("model", [PointsModel])
@pytest.mark.parametrize("instance_key", [None, "cell_id"])
Expand Down
Loading