fix: render unannotated shapes with na_color instead of dropping them#711
Merged
Conversation
ec8b016 to
e34f7db
Compare
…dropping them (#710) render_shapes joined the element to its table with how="inner", silently dropping shapes whose instance had no table row. Points (how="left" merge) and labels (raster + na_color) keep unannotated elements, so shapes were the inconsistent outlier (and it broke the labels<->shapes interchangeability). Switch _join_table_for_element to how="left": all shapes survive, and the per-shape color lookup (_extract_color_column, reindexed to the element) yields NaN -> na_color for the unannotated ones, via the existing NaN-handling path. Fully-annotated data is unaffected (verified pixel-identical: inner == left when nothing is dropped), so only partial-annotation output changes. Adds two visual regression tests: coloring blobs_polygons by a table column renders the unannotated polygon (instance 0, no table row) with na_color instead of dropping it, and na_color=None hides it again. polygon (instance 0 has no table row) with na_color instead of dropping it.
Unannotated shapes now render with na_color (non_matching_table, fill_and_outline, custom_colors_from_uns), and the element keeps its original draw order instead of the inner-join's scramble (the shuffling/queried tests). All renders verified correct against the new behavior.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #711 +/- ##
==========================================
- Coverage 76.42% 76.39% -0.03%
==========================================
Files 14 14
Lines 4330 4330
Branches 1006 1006
==========================================
- Hits 3309 3308 -1
Misses 664 664
- Partials 357 358 +1
🚀 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.
Closes #710.
What
render_shapescolored by a table column silently dropped shapes whose instance had no row in the table (_join_table_for_element(how="inner")). This renders them withna_colorinstead — consistent with the points (how="left"merge) and labels (raster + na_color) paths, and with the scanpy/squidpy convention.How
One-line behavior change:
_join_table_for_elementuseshow="left"instead ofhow="inner", so every shape survives the join. The per-shape color lookup (_extract_color_column, from #709, reindexed to the element) then yieldsNaN → na_colorfor the unannotated shapes via the existing NaN-handling path (which also emits the existing "Found N NaN values… colored with na_color" warning). No new color logic.Scope / safety
inner == leftwhen nothing is dropped) for continuous, categorical, and gene coloring. So existing visual baselines should not change; only partial-annotation fixtures (if any) change — those would be a deliberate, reviewable baseline update._extract_color_column), which is already onmain.Test
Adds
test_render_shapes_unannotated_shapes_get_na_color_not_dropped— a real regression test: it fails on the old code (expected all 20 shapes rendered, got 12 (unannotated dropped)) and passes on the fix (20 rendered, 8 in na_color). There was previously no test covering this behavior, which is why the inconsistency went unnoticed.