Skip to content

Fix categorical color mapping across coordinate systems#547

Open
timtreis wants to merge 1 commit intomainfrom
fix/425-categorical-color-mapping-across-cs
Open

Fix categorical color mapping across coordinate systems#547
timtreis wants to merge 1 commit intomainfrom
fix/425-categorical-color-mapping-across-cs

Conversation

@timtreis
Copy link
Member

Summary

  • Fixes ValueError: zip() argument 2 is shorter than argument 1 when plotting shapes colored by a categorical column across multiple coordinate systems with different category counts
  • Calls remove_unused_categories() early in _generate_base_categorial_color_mapping and _extract_colors_from_table_uns so that categories and stored .uns colors stay aligned
  • Uses category position in the full table (not the subset) for color lookup, ensuring consistent coloring across coordinate systems

Fixes #425

Test plan

  • Verify plotting shapes with color="leiden" across multiple coordinate systems where category counts differ no longer crashes
  • Verify colors remain consistent (same category gets same color) regardless of which coordinate system is being rendered
  • Verify no regression when all categories are present in every coordinate system

🤖 Generated with Claude Code

…rdinate systems

When plotting shapes colored by a categorical column across multiple
coordinate systems, the color_source_vector could carry unused categories
from other coordinate systems. This caused a length mismatch between
categories and stored colors in adata.uns, leading to a ValueError in
strict zip calls.

The fix removes unused categories early in both _generate_base_categorial_color_mapping
and _extract_colors_from_table_uns, and maps colors by the category's position in the
full table (not the subset) to ensure consistent coloring across coordinate systems.

Fixes #425

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@codecov-commenter
Copy link

codecov-commenter commented Mar 10, 2026

Codecov Report

❌ Patch coverage is 42.85714% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.86%. Comparing base (a2bb56b) to head (ec09641).

Files with missing lines Patch % Lines
src/spatialdata_plot/pl/utils.py 42.85% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #547      +/-   ##
==========================================
- Coverage   84.00%   83.86%   -0.15%     
==========================================
  Files           9        9              
  Lines        2601     2609       +8     
==========================================
+ Hits         2185     2188       +3     
- Misses        416      421       +5     
Files with missing lines Coverage Δ
src/spatialdata_plot/pl/utils.py 79.08% <42.85%> (-0.23%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Render shapes fails for categoricals of different length across coordinate systems

2 participants