Skip to content

Added guard against annotated instance_id==0 elements in render_labels#660

Merged
timtreis merged 2 commits into
scverse:mainfrom
SAY-5:SAY-5/fix/labels-background-instance-id
May 12, 2026
Merged

Added guard against annotated instance_id==0 elements in render_labels#660
timtreis merged 2 commits into
scverse:mainfrom
SAY-5:SAY-5/fix/labels-background-instance-id

Conversation

@SAY-5
Copy link
Copy Markdown
Contributor

@SAY-5 SAY-5 commented May 12, 2026

Closes #607.

When the annotation table for render_labels includes a row with instance_id=0, downstream masking would fail with IndexError: Boolean index has wrong length from inside the color-vector path: SpatialData's foreground-only get_values returned one fewer entry than the table's instance_id array, and the mask at render.py:1673 mismatched. Nothing in the traceback mentioned background label 0.

Added an explicit check after the table is subset to the element: if instance_id=0 is present, raise a ValueError naming the table, element, and the fix (remove the row). Regression test in test_render_labels.py.

Closes scverse#607.

Signed-off-by: SAY-5 <say.apm35@gmail.com>
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.50%. Comparing base (53abe71) to head (f3eea16).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #660   +/-   ##
=======================================
  Coverage   77.50%   77.50%           
=======================================
  Files          11       11           
  Lines        3569     3574    +5     
  Branches      837      839    +2     
=======================================
+ Hits         2766     2770    +4     
  Misses        481      481           
- Partials      322      323    +1     
Files with missing lines Coverage Δ
src/spatialdata_plot/pl/render.py 87.34% <100.00%> (+0.03%) ⬆️

... 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 changed the title fix: raise on instance_id=0 in render_labels annotation table Added guard against annotated instance_id==0 elements in render_labels May 12, 2026
@timtreis timtreis merged commit 7f3e7ad into scverse:main May 12, 2026
6 of 7 checks passed
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.

render_labels crashes with IndexError when table includes instance_id=0 (background label)

3 participants