Skip to content

Commit 24ce1c5

Browse files
committed
Tighten verbose docstrings and comments
Drop multi-paragraph regression-narrative blocks in favor of one-line docstrings naming the invariant under test. Strip restating-the-bug inline comments inside parametrize tables.
1 parent b7199f3 commit 24ce1c5

3 files changed

Lines changed: 10 additions & 29 deletions

File tree

src/spatialdata_plot/pl/_datashader.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,10 @@
4444

4545

4646
def _apply_user_alpha(result: ds.tf.Image | np.ndarray, alpha: float) -> ds.tf.Image | np.ndarray:
47-
"""Multiply the alpha channel of a datashader shade result by ``alpha``.
47+
"""Scale the alpha channel of a datashader shade result by ``alpha``.
4848
49-
``ds.tf.shade(min_alpha=...)`` is a floor on the alpha of non-empty pixels,
50-
not a scaling factor, so user-supplied ``fill_alpha`` / ``alpha`` must be
51-
applied post-hoc to match the matplotlib path. See #617.
49+
``ds.tf.shade(min_alpha=...)`` is a floor, not a scale, so user alpha
50+
must be applied post-hoc. See #617.
5251
"""
5352
if alpha >= 1.0 or result is None:
5453
return result

tests/pl/test_render_shapes.py

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,13 +1238,7 @@ def test_datashader_alpha_not_applied_twice(sdata_blobs: SpatialData):
12381238
],
12391239
)
12401240
def test_datashader_respects_fill_alpha(sdata_blobs: SpatialData, fill_alpha: float, expected_max: int):
1241-
"""Datashader must apply fill_alpha as a multiplicative scale on the rendered alpha.
1242-
1243-
Regression test for https://github.com/scverse/spatialdata-plot/issues/617.
1244-
Before the fix, ``fill_alpha`` was passed only as ``ds.tf.shade(min_alpha=...)``,
1245-
which is a floor on alpha for non-empty pixels rather than a scaling factor, so
1246-
shapes always rendered at alpha=255 regardless of ``fill_alpha`` (including 0.0).
1247-
"""
1241+
"""fill_alpha must scale the rendered alpha channel linearly on the datashader path (#617)."""
12481242
fig, ax = plt.subplots()
12491243
sdata_blobs.pl.render_shapes(
12501244
element="blobs_polygons",
@@ -1264,20 +1258,14 @@ def test_datashader_respects_fill_alpha(sdata_blobs: SpatialData, fill_alpha: fl
12641258
@pytest.mark.parametrize(
12651259
("outline_alpha", "expected_max"),
12661260
[
1267-
(0.0, None), # no outline image is rendered
1261+
(0.0, None),
12681262
(0.3, 76),
12691263
(0.5, 127),
12701264
(1.0, 255),
12711265
],
12721266
)
12731267
def test_datashader_respects_outline_alpha(sdata_blobs: SpatialData, outline_alpha: float, expected_max: int | None):
1274-
"""Datashader must apply outline_alpha as a multiplicative scale on the rendered alpha.
1275-
1276-
Regression test for https://github.com/scverse/spatialdata-plot/issues/617.
1277-
Same root cause as fill_alpha: ``outline_alpha`` was passed only as
1278-
``ds.tf.shade(min_alpha=...)``, which is a floor on alpha for non-empty pixels,
1279-
so outlines always rendered with max alpha=255 regardless of ``outline_alpha``.
1280-
"""
1268+
"""outline_alpha must scale the outline image's alpha; alpha=0 must skip rendering entirely (#617)."""
12811269
fig, ax = plt.subplots()
12821270
sdata_blobs.pl.render_shapes(
12831271
element="blobs_polygons",
@@ -1289,18 +1277,16 @@ def test_datashader_respects_outline_alpha(sdata_blobs: SpatialData, outline_alp
12891277
fig.canvas.draw()
12901278

12911279
axes_images = [c for c in ax.get_children() if isinstance(c, matplotlib.image.AxesImage)]
1292-
# The outline is rendered red on top of the (gray) fill; pick the red one.
12931280
outline_imgs = [
12941281
img
12951282
for img in axes_images
12961283
if (arr := img.get_array()).ndim == 3 and arr.shape[-1] == 4 and arr[..., 0].max() > arr[..., 1].max()
12971284
]
12981285
if expected_max is None:
1299-
assert not outline_imgs, "outline_alpha=0 should not render an outline image"
1286+
assert not outline_imgs
13001287
else:
1301-
assert outline_imgs, "no outline AxesImage found"
1302-
rgba = outline_imgs[0].get_array()
1303-
assert int(rgba[..., 3].max()) == expected_max
1288+
assert outline_imgs
1289+
assert int(outline_imgs[0].get_array()[..., 3].max()) == expected_max
13041290
plt.close(fig)
13051291

13061292

tests/pl/test_utils.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,19 +169,15 @@ def test_is_color_like(color_result: tuple[ColorLike, bool]):
169169
@pytest.mark.parametrize(
170170
("outline_alpha", "outline_color", "expected"),
171171
[
172-
# Explicit outline_alpha=0.0 with outline_color: previously a falsy
173-
# short-circuit (`outline_alpha and outline_alpha == 0.0`) caused
174-
# outline_alpha=0.0 to be silently remapped to (1.0, 1.0), rendering
175-
# the outline anyway. Regression test for the #617 follow-up.
176172
(0.0, Color("#ff0000"), (0.0, 0.0)),
177173
(0, Color("#ff0000"), (0.0, 0.0)),
178174
((0.0, 0.0), Color("#ff0000"), (0.0, 0.0)),
179-
# Sanity: positive alphas still produce a visible outline.
180175
(0.5, Color("#ff0000"), (0.5, 0.0)),
181176
(1.0, Color("#ff0000"), (1.0, 0.0)),
182177
],
183178
)
184179
def test_set_outline_respects_zero_alpha(outline_alpha, outline_color, expected):
180+
"""outline_alpha=0 must yield (0.0, 0.0) even when outline_color is set (#617 follow-up)."""
185181
alpha, _ = _set_outline(outline_alpha=outline_alpha, outline_width=None, outline_color=outline_color)
186182
assert alpha == expected
187183

0 commit comments

Comments
 (0)