Skip to content

Fix categorical colors wrongly assigned to points with non-sequential index#570

Merged
timtreis merged 1 commit intomainfrom
fix/issue-358-categorical-color-alignment
Mar 31, 2026
Merged

Fix categorical colors wrongly assigned to points with non-sequential index#570
timtreis merged 1 commit intomainfrom
fix/issue-358-categorical-color-alignment

Conversation

@timtreis
Copy link
Copy Markdown
Member

@timtreis timtreis commented Mar 30, 2026

Summary

  • Fixes Categorical colors wrongly assigned to points #358: when points have a non-sequential index (e.g. from .sample() or .subset()), categorical colors were assigned based on sorted index order instead of actual row order, causing colors to appear shuffled.
  • Root cause: _reparse_points() round-trips through PointsModel.parse which sorts by index, but adata.X retained the original unsorted order. get_values() then returned colors in sorted order — misaligned with coordinates.
  • Fix: reset the points index to sequential before adata construction and reparsing so both share the same positional order.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.61%. Comparing base (55d59b7) to head (d3ca5ba).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #570      +/-   ##
==========================================
+ Coverage   75.39%   75.61%   +0.22%     
==========================================
  Files          10       10              
  Lines        2906     2908       +2     
  Branches      672      672              
==========================================
+ Hits         2191     2199       +8     
+ Misses        431      428       -3     
+ Partials      284      281       -3     
Files with missing lines Coverage Δ
src/spatialdata_plot/pl/render.py 86.85% <100.00%> (+0.02%) ⬆️

... and 2 files 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 force-pushed the fix/issue-358-categorical-color-alignment branch 5 times, most recently from a782851 to bfb1ef2 Compare March 30, 2026 22:55
… index (#358)

When points have a shuffled or non-sequential index (e.g. from .sample()
or .subset()), _reparse_points sorts rows by index while adata.X retains
the original order. This causes get_values to return colors in sorted
order, misaligned with coordinates. Resetting the index to sequential
before adata construction and reparsing ensures both share the same
positional order.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@timtreis timtreis force-pushed the fix/issue-358-categorical-color-alignment branch from bfb1ef2 to d3ca5ba Compare March 30, 2026 23:05
@timtreis timtreis merged commit 367204d into main Mar 31, 2026
8 checks passed
@timtreis timtreis deleted the fix/issue-358-categorical-color-alignment branch March 31, 2026 09:13
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.

Categorical colors wrongly assigned to points

2 participants