fix(labels): align instance_id with colour vector for partial tables (#775) - #776
Open
timtreis wants to merge 1 commit into
Open
fix(labels): align instance_id with colour vector for partial tables (#775)#776timtreis wants to merge 1 commit into
timtreis wants to merge 1 commit into
Conversation
…775) render_labels(color=...) raised IndexError when the annotating table had rows for instances absent from the labels (e.g. objects lost when a segmentation is regenerated, or a table from an upstream pipeline). instance_id was derived from all table rows, but the colour vector from get_values is restricted to the element's present instances, so the two diverged and the rasterize mask indexed the shorter colour vector. Restrict instance_id to the canonical instances actually present in the element (get_element_instances) intersected with the table, matching the colour vector's basis independent of rasterize/multiscale display drops. Claude-Session: https://claude.ai/code/session_01U9J5GSXR4XGjPMaQQR5iSj
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #776 +/- ##
=======================================
Coverage 80.09% 80.09%
=======================================
Files 18 18
Lines 4863 4863
Branches 1080 1080
=======================================
Hits 3895 3895
Misses 603 603
Partials 365 365
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
render_labels(color=...)raisesIndexErrorwhen the annotating table has rows for instances that are not present in the labels element — e.g. objects lost when a segmentation is regenerated, or a table read from an upstream pipeline.Fixes #775.
Root cause
instance_idwas derived from all table rows (np.unique(table.obs[instance_key])), but the colour vector fromget_valuesis restricted to the element's present instances. The two diverged, so the rasterize mask (length = number of table rows) indexed the shorter colour vector →IndexErroratrender.py→_color.pyColorSpec.filter.This was only ever half-fixed: #603/#661 added
_check_instance_ids_overlap, but that raises only when the ID sets are fully disjoint. Shapes/points already reindex colour to the element index and are robust to phantom rows; labels was left behind.Fix
Restrict
instance_idto the canonical instances actually present in the element (get_element_instances) intersected with the table — the same basisget_valuesuses for the colour vector, independent of the rendered scale:Rasterize / multiscale display drops are still reconciled against both vectors by the existing mask further down, so alignment holds in all cases.
Behaviour
color) now render as missing instead of raising.intersectequals the oldnp.unique(table.obs)there).get_element_instancesscan on the coloured-labels path.Tests
tests/pl/test_render_labels.py: parametrized phantom-row + present-not-in-table × continuous/categorical, plus a rasterize-survival case. All fail onmain(IndexError) and pass with the fix. Full non-visual labels suite: 35 passed.https://claude.ai/code/session_01U9J5GSXR4XGjPMaQQR5iSj