Skip to content

Fix misleading cmap errors when norm/palette interact#653

Merged
timtreis merged 1 commit intomainfrom
fix/issue-622-norm-cmap-palette-errors
May 8, 2026
Merged

Fix misleading cmap errors when norm/palette interact#653
timtreis merged 1 commit intomainfrom
fix/issue-622-norm-cmap-palette-errors

Conversation

@timtreis
Copy link
Copy Markdown
Member

@timtreis timtreis commented May 8, 2026

Closes #622.

Summary

Three related defects all surfaced as errors blaming cmap for a norm/palette mistake the user never made:

  1. norm=[n1, n2] for a 3-channel image raised "If 'cmap' is provided, its length must match the number of channels." even though the user only passed norm=.
  2. cmap=[...] of wrong length combined with norm= of correct length silently nulled the cmap and rendered with the default — asymmetric with the no-norm path which raises.
  3. palette=[...] + norm=[...] (per-channel norms) raised "If 'palette' is provided, 'cmap' must be None." even though the user never passed cmap.

Fixes

  • utils.py::_validate_image_render_params: validate norm-list length against the channel count up front with a norm-specific error message; reject wrong-length cmap instead of silently nulling it.
  • render.py: distinguish user-supplied multi-cmaps from the default-cmap list synthesized by basic.py to carry per-channel norms (via CmapParams.cmap_is_default). The palette/cmap conflict and the "blending multiple cmaps" warning now fire only when at least one cmap is user-supplied. The palette + norm=list case falls through to the palette path; per-channel norms are already applied to the layers in the per-channel norm loop.

@timtreis timtreis force-pushed the fix/issue-622-norm-cmap-palette-errors branch from e0cc677 to a5dfd13 Compare May 8, 2026 17:12
Three related defects all manifested as errors blaming `cmap` for a
`norm`/`palette` mistake the user never made:

1. `norm=[n1, n2]` for a 3-channel image raised "If 'cmap' is provided,
   its length must match the number of channels." even though the user
   only passed `norm=`. _validate_image_render_params now validates the
   norm-list length against the channel count up front, with a
   norm-specific error message.

2. `cmap=["Reds","Greens"]` (wrong length) combined with `norm=` of
   correct length silently nulled the cmap and used the default. The
   wrong-length cmap is now rejected uniformly, matching the no-norm
   path.

3. `palette + norm=list` raised "If 'palette' is provided, 'cmap' must
   be None." because basic.py auto-expanded a default-cmap list to carry
   the per-channel norms, and render.py couldn't tell the synthesized
   list apart from a user-supplied one. The render path now keys the
   palette/cmap conflict on whether any CmapParams was actually
   user-supplied (cmap_is_default=False); the synthesized default-cmap
   list falls through to the palette path, where per-channel norms are
   already applied to the layers.

The "blending multiple cmaps" warning is also gated on user-supplied
cmaps, so it no longer fires spuriously when the user only set `norm`
or `palette + norm=list`.
@timtreis timtreis force-pushed the fix/issue-622-norm-cmap-palette-errors branch from a5dfd13 to 8ddfffa Compare May 8, 2026 17:19
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.99%. Comparing base (e107c0a) to head (8ddfffa).

Files with missing lines Patch % Lines
src/spatialdata_plot/pl/render.py 77.77% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #653      +/-   ##
==========================================
+ Coverage   76.89%   76.99%   +0.09%     
==========================================
  Files          11       11              
  Lines        3277     3282       +5     
  Branches      774      775       +1     
==========================================
+ Hits         2520     2527       +7     
+ Misses        457      455       -2     
  Partials      300      300              
Files with missing lines Coverage Δ
src/spatialdata_plot/pl/utils.py 67.43% <100.00%> (+0.18%) ⬆️
src/spatialdata_plot/pl/render.py 87.18% <77.77%> (+0.33%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@timtreis timtreis merged commit 4606ef0 into main May 8, 2026
7 of 8 checks passed
@timtreis timtreis deleted the fix/issue-622-norm-cmap-palette-errors branch May 8, 2026 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Misleading 'cmap' errors when norm= list has wrong length or palette + norm are combined

2 participants