Warn when groups values don't match color categories#556
Merged
Conversation
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 Report❌ Patch coverage is
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
🚀 New features to boost your workflow:
|
- 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>
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.
Summary
groupscontains values not found in thecolorcolumn's categories, so users understand why their plot is empty (closes Plotting Leiden clusters, coloring by cell cycle phase, throws KeyError: 'geometry' #455)_get_collection_shapeto return an emptyPatchCollectioninstead of crashing withKeyError: 'geometry'The original crash was fixed in #549, but users still got no feedback when
groupsvalues didn't match. This adds a clear warning message explaining thatgroupsfilters values of thecolorcolumn.