Skip to content

Commit 4eb263a

Browse files
timtreisclaude
andcommitted
Eliminate post-hoc cmap_params unwrap, shorten effective_cmap comment
Restructure branching so scalar cmap_params is built directly when there's only one cmap (len <= 1), instead of building a list and unwrapping after. Also handles norm=[single_Normalize] gracefully by extracting the scalar. Shortens the effective_cmap comment to one line. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent a48e3e6 commit 4eb263a

1 file changed

Lines changed: 14 additions & 14 deletions

File tree

src/spatialdata_plot/pl/basic.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -632,11 +632,9 @@ def render_images(
632632

633633
for element, param_values in params_dict.items():
634634
cmap_params: list[CmapParams] | CmapParams
635-
# Use the resolved per-element cmap when the user passed a norm list,
636-
# so that auto-replicated cmaps are correctly zipped with per-channel norms.
637-
# Otherwise preserve the original user-supplied cmap for branching.
635+
# Resolve which cmap to use for norm-list path vs scalar path.
638636
effective_cmap = param_values.get("cmap") if isinstance(norm, list) else cmap
639-
if isinstance(effective_cmap, list):
637+
if isinstance(effective_cmap, list) and len(effective_cmap) > 1:
640638
if isinstance(norm, list):
641639
if len(norm) != len(effective_cmap):
642640
raise ValueError(
@@ -657,20 +655,22 @@ def render_images(
657655

658656
else:
659657
if isinstance(norm, list):
660-
raise ValueError(
661-
"When 'norm' is a list, you must also pass a list of colormaps via 'cmap' "
662-
"with matching length, or use a single Normalize."
663-
)
658+
if len(norm) == 1:
659+
norm_scalar: Normalize | None = norm[0]
660+
else:
661+
raise ValueError(
662+
"When 'norm' is a list, you must also pass a list of colormaps via 'cmap' "
663+
"with matching length, or use a single Normalize."
664+
)
665+
else:
666+
norm_scalar = norm
667+
scalar_cmap = effective_cmap[0] if isinstance(effective_cmap, list) else cmap
664668
cmap_params = _prepare_cmap_norm(
665-
cmap=cmap,
666-
norm=norm,
669+
cmap=scalar_cmap,
670+
norm=norm_scalar,
667671
na_color=param_values["na_color"],
668672
**kwargs,
669673
)
670-
# Unwrap length-1 list so the single-channel rendering path
671-
# (which checks `not isinstance(cmap_params, list)`) still works.
672-
if isinstance(cmap_params, list) and len(cmap_params) == 1:
673-
cmap_params = cmap_params[0]
674674
sdata.plotting_tree[f"{n_steps + 1}_render_images"] = ImageRenderParams(
675675
element=element,
676676
channel=param_values["channel"],

0 commit comments

Comments
 (0)