Skip to content

Commit 5b1f7e3

Browse files
timtreisclaude
andcommitted
Clean up test: module-level import, remove stale line refs, pin exception type
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 46b80ce commit 5b1f7e3

1 file changed

Lines changed: 10 additions & 14 deletions

File tree

tests/pl/test_render_shapes.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from shapely.geometry import MultiPolygon, Point, Polygon
1414
from spatialdata import SpatialData, deepcopy
1515
from spatialdata.models import ShapesModel, TableModel
16-
from spatialdata.transformations import Affine, Identity, MapAxis, Scale, Sequence, Translation
16+
from spatialdata.transformations import Affine, Identity, MapAxis, Scale, Sequence, Translation, set_transformation
1717
from spatialdata.transformations._utils import _set_transformations
1818

1919
import spatialdata_plot # noqa: F401
@@ -1071,12 +1071,10 @@ def test_groups_filtering_preserves_transformation(sdata_blobs: SpatialData):
10711071
"""Regression test for #420: groups filtering must not strip coordinate-system metadata.
10721072
10731073
Simulates the exact sequence that ``_render_shapes`` performs —
1074-
``filter_by_coordinate_system`` ➜ groups boolean-index ➜ ``reset_index`` ➜
1075-
re-assign to ``sdata_filt`` — then asserts that ``_prepare_transformation``
1076-
can still retrieve the non-global transformation with the correct scale.
1074+
filter_by_coordinate_system -> groups boolean-index -> reset_index ->
1075+
re-assign to sdata_filt -> GeoDataFrame re-wrap — then asserts that
1076+
``_prepare_transformation`` can still retrieve the correct transformation.
10771077
"""
1078-
from spatialdata.transformations import set_transformation
1079-
10801078
from spatialdata_plot.pl.utils import _prepare_transformation
10811079

10821080
scale_factor = 2.5
@@ -1090,25 +1088,23 @@ def test_groups_filtering_preserves_transformation(sdata_blobs: SpatialData):
10901088

10911089
sdata_filt = sdata_blobs.filter_by_coordinate_system(coordinate_system=cs, filter_tables=False)
10921090

1093-
# --- replicate the groups-filtering path from _render_shapes (lines 382-389) ---
1091+
# Replicate groups filtering: boolean-index -> reset_index -> re-assign
10941092
shapes = sdata_filt.shapes["blobs_polygons"]
10951093
keep = shapes["cluster"] == "c1"
10961094
shapes = shapes[keep].reset_index(drop=True)
10971095
sdata_filt["blobs_polygons"] = shapes
1098-
# also replicate the GeoDataFrame re-wrap that follows (line 432), which strips .attrs
1096+
# GeoDataFrame re-wrap strips .attrs (this is what _render_shapes does next)
10991097
shapes = gpd.GeoDataFrame(shapes, geometry="geometry")
11001098

1101-
# The sdata_filt element must still carry the correct transformation
1102-
# (this is where _render_shapes reads the transform after the fix).
1099+
# sdata_filt's element must still carry the correct transformation
11031100
trans, _ = _prepare_transformation(sdata_filt.shapes["blobs_polygons"], cs)
11041101
matrix = trans.get_matrix()
11051102
np.testing.assert_allclose(matrix[0, 0], scale_factor, err_msg="x-scale lost after groups filtering")
11061103
np.testing.assert_allclose(matrix[1, 1], scale_factor, err_msg="y-scale lost after groups filtering")
11071104

1108-
# The GeoDataFrame re-wrap (which _render_shapes does right after) strips
1109-
# attrs — prove that reading the transform from *that* object would fail,
1110-
# demonstrating why early capture matters.
1111-
with pytest.raises((KeyError, AssertionError)):
1105+
# The GeoDataFrame re-wrap strips attrs — reading the transform from
1106+
# the re-wrapped object must fail, proving why early capture matters.
1107+
with pytest.raises(AssertionError):
11121108
_prepare_transformation(shapes, cs)
11131109

11141110

0 commit comments

Comments
 (0)