Skip to content

Raise on obs/var key collision in table-based coloring#678

Merged
timtreis merged 3 commits into
mainfrom
fix/issue-621
May 20, 2026
Merged

Raise on obs/var key collision in table-based coloring#678
timtreis merged 3 commits into
mainfrom
fix/issue-621

Conversation

@timtreis
Copy link
Copy Markdown
Member

@timtreis timtreis commented May 20, 2026

Summary

  • Fix obs column silently shadows var gene expression when key exists in both #621: when a key existed in both table.obs.columns and table.var_names, upstream _get_table_origins's elif chain returned only the obs origin and the user silently got obs values instead of gene expression.
  • Add _check_obs_var_shadow in pl/utils.py, called from _render_shapes/_render_points/_render_labels before any value fetch (the table's var_names are clobbered later in the rendering pipeline, so the check must run early).
  • Raise a descriptive ValueError naming both obs.columns and var_names and pointing at the table key, so the user can rename or drop one side.

timtreis added 3 commits May 20, 2026 22:51
When the same key existed in both `table.obs.columns` and `table.var_names`,
upstream `_get_table_origins` returned only the obs origin (elif chain),
silently masking gene expression with obs values. Catch the collision at
the renderer entry points and raise a descriptive ValueError naming both
locations so the user can disambiguate.

Fixes #621
- Use `get_element_annotators` instead of hand-rolling the table-annotates-
  element check via `table.uns["spatialdata_attrs"]["region"]`.
- Drop unused `TableModel` import.
- Align error message phrasing with the existing `_check_color_column_collision`
  pattern (`` `color=...` is ambiguous ``).
@timtreis timtreis merged commit 75cadce into main May 20, 2026
7 of 8 checks passed
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.81818% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.71%. Comparing base (3ebefe1) to head (cb2bdfb).

Files with missing lines Patch % Lines
src/spatialdata_plot/pl/utils.py 75.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #678      +/-   ##
==========================================
- Coverage   77.72%   77.71%   -0.02%     
==========================================
  Files          11       11              
  Lines        3641     3652      +11     
  Branches      860      863       +3     
==========================================
+ Hits         2830     2838       +8     
- Misses        486      487       +1     
- Partials      325      327       +2     
Files with missing lines Coverage Δ
src/spatialdata_plot/pl/render.py 87.32% <100.00%> (+0.04%) ⬆️
src/spatialdata_plot/pl/utils.py 67.96% <75.00%> (-0.03%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@timtreis timtreis deleted the fix/issue-621 branch May 20, 2026 21:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

obs column silently shadows var gene expression when key exists in both

2 participants