Skip to content

Warn when groups values don't match color categories#556

Merged
timtreis merged 3 commits intomainfrom
fix/issue-455-defensive-guards
Mar 23, 2026
Merged

Warn when groups values don't match color categories#556
timtreis merged 3 commits intomainfrom
fix/issue-455-defensive-guards

Conversation

@timtreis
Copy link
Member

@timtreis timtreis commented Mar 23, 2026

Summary

The original crash was fixed in #549, but users still got no feedback when groups values didn't match. This adds a clear warning message explaining that groups filters values of the color column.

When `groups` contains values absent from the `color` column's categories,
emit a warning so users understand why the plot is empty. Also add a
defensive empty-input guard in `_get_collection_shape` to prevent a
`KeyError: 'geometry'` if an empty DataFrame ever reaches PatchCollection
construction.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@codecov-commenter
Copy link

codecov-commenter commented Mar 23, 2026

Codecov Report

❌ Patch coverage is 76.92308% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.89%. Comparing base (23010b9) to head (f15f0e0).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/spatialdata_plot/pl/render.py 83.33% 4 Missing ⚠️
src/spatialdata_plot/pl/utils.py 0.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #556      +/-   ##
==========================================
+ Coverage   73.87%   73.89%   +0.01%     
==========================================
  Files          10       10              
  Lines        2752     2777      +25     
  Branches      639      645       +6     
==========================================
+ Hits         2033     2052      +19     
- Misses        446      451       +5     
- Partials      273      274       +1     
Files with missing lines Coverage Δ
src/spatialdata_plot/pl/utils.py 65.48% <0.00%> (-0.09%) ⬇️
src/spatialdata_plot/pl/render.py 82.14% <83.33%> (+0.02%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

timtreis and others added 2 commits March 24, 2026 00:07
- Extract `_warn_missing_groups` helper and call it from
  `_filter_groups_transparent_na` (shapes/points) and inline in labels,
  removing duplicated logic from both call sites.
- Distinguish "none matched" (likely wrong column) from "some missing"
  (likely typo) with different warning messages.
- Replace assert with explicit `color_source_vector is not None` guard
  in the shapes condition, matching the points pattern.
- Add 4 tests (shapes + points × all-missing + partial-missing) using
  `logger_warns` to lock the warning behavior.
- Drop `**kwargs` from empty `PatchCollection` fallback.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Move _warn_missing_groups call before the na_color guard so the
  warning fires regardless of na_color (not just when na_color is
  transparent).
- Remove col_for_color param from _filter_groups_transparent_na
  (warning is no longer its responsibility).
- Fix fallback column label: "in column." → "in the color column."
- Guard sorted() with try/except for non-sortable category types.
- Deduplicate set(groups_list) into a single groups_set variable.
- Parametrize tests over na_color=[None, "red"] to cover both paths.
- Add labels warning test.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@timtreis timtreis merged commit edca5a5 into main Mar 23, 2026
8 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.

Plotting Leiden clusters, coloring by cell cycle phase, throws KeyError: 'geometry'

2 participants