fix: clear error on disjoint instance IDs in render_shapes/labels/points#661
fix: clear error on disjoint instance IDs in render_shapes/labels/points#661SAY-5 wants to merge 1 commit into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #661 +/- ##
==========================================
+ Coverage 77.54% 77.57% +0.02%
==========================================
Files 11 11
Lines 3572 3581 +9
Branches 838 840 +2
==========================================
+ Hits 2770 2778 +8
Misses 480 480
- Partials 322 323 +1
🚀 New features to boost your workflow:
|
| if _saved_index_name is not None and _saved_index_name in _obs.columns: | ||
| _obs.index.name = None | ||
|
|
||
| # Guard against a disjoint instance_key (#603): when no table rows annotate any element |
There was a problem hiding this comment.
Claude tends to be overly verbose, please remove this comment
|
|
||
|
|
||
| def test_render_shapes_disjoint_instance_ids_clear_error(): | ||
| # Regression test for #603: when a table annotates the element (region key matches) but no |
There was a problem hiding this comment.
This is also overly verbose, reduce to one-liner
|
Hey @SAY-5, thanks for your contribution. Few issues with this PR: Your new guard sits between the _obs.index.name = None workaround and the try/finally that restores it. If the guard raises, the sdata[table_name].obs.index.name is left mutated which is a problem. Also, this fix only applies to shapes, the same behaviour can happen for labels and points, so we'd need the same fix there. |
| # Regression test for #603: when a table annotates the element (region key matches) but no | ||
| # instance_id values overlap, the call used to crash with a bare `KeyError: None` from deep | ||
| # inside spatialdata's join path. Replace with a clear, actionable ValueError. | ||
| from shapely.geometry import Point |
There was a problem hiding this comment.
Don't reimport inside the test
| # Guard against a disjoint instance_key (#603): when no table rows annotate any element | ||
| # row, the upstream join crashes with `KeyError: None` from deep inside pandas. Raise | ||
| # a clear, actionable ValueError before invoking the join. | ||
| _, _region_key, _instance_key = get_table_keys(sdata[table_name]) |
There was a problem hiding this comment.
Operate on sdata_filt instead of sdata here
5a5900e to
95fc089
Compare
|
Thanks for the review. Reworked in 95fc089:
Also retitled the PR to reflect the wider scope. |
|
Hey @SAY-5, thanks for the update! I had also left some more comments in the code directly that aren't yet addressed, also, the branch has conflicts with main. Would be great if you could finalise the PR 👍 Thanks! |
95fc089 to
65aed4d
Compare
|
Rebased onto current main (resolved a conflict in tests/pl/test_render_labels.py by keeping both the new instance_id==0 background guard test from #660 and this PR's disjoint-instance-ID regression test). ruff check and ruff format pass; the full non-plot test suite for test_render_shapes/labels/points (78 tests, including the 3 regression tests added here) passes locally. Ready for another look. |
65aed4d to
ebeb67a
Compare
|
Addressed the inline notes: trimmed the verbose comments to one line, dropped the redundant in-test |
ebeb67a to
2e33801
Compare
|
Switched the overlap check to operate on sdata_filt and dropped the verbose comments. Rebased on main so there are no conflicts. New regression tests pass locally. |
Closes #603.
When a table annotates the element (region key matches) but no
instance_idvalues overlap, the call crashed with a bareKeyError: Nonefrom deep inside upstreamspatialdata's join path. The traceback gave no indication that the instance ID sets were disjoint.Added an explicit disjoint check before
join_spatialelement_table: when at least one table row claims to annotate the element yet theinstance_keyvalues share nothing with the element's index, raise aValueErrornaming the table, element, instance key, and the fix. Regression test intest_render_shapes.py.