fix: guard bw conversion in pl.spatial against missing image#4207
Open
steps-re wants to merge 1 commit into
Open
fix: guard bw conversion in pl.spatial against missing image#4207steps-re wants to merge 1 commit into
steps-re wants to merge 1 commit into
Conversation
sc.pl.spatial raises TypeError when bw=True is passed without an image (no img argument and no image in .uns['spatial']). _check_img ran the grayscale conversion unconditionally on bw=True, indexing img even when it was still None. Skip the conversion when there's no image to convert. Signed-off-by: Mike German <mike@stepsventures.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4207 +/- ##
==========================================
- Coverage 79.91% 79.87% -0.04%
==========================================
Files 121 121
Lines 12949 12949
==========================================
- Hits 10348 10343 -5
- Misses 2601 2606 +5
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Author
|
Heads up on the red CI: the only failing test is |
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
sc.pl.spatial(..., bw=True)raisesTypeError: 'NoneType' object is not subscriptablewhen called without an image (noimgpassed and no image available in.uns['spatial'], e.g. general spatial coordinates without a background image)._check_imgruns the grayscale conversion unconditionally wheneverbw=True:If
imgis stillNoneat that point, indexing it crashes. The existing test suite already documents this gap:test_manual_equivalency_no_imgskips thebwcase with the comment "Has no meaning when there is no image" instead of asserting it works.Fix
Guard the conversion on
img is not None, matching how the rest of_check_imgand_check_na_colortreat a possibly-missing image.Test plan
test_spatial_bw_no_img, exercisingsc.pl.spatial(..., bw=True)on data with no image anywhere, confirming it no longer raises.tests/test_plotting_embedded/suite passes locally (117 passed, 5 skipped, no change to skip count).ruff checkclean on changed files.docs/release-notes/4207.fix.md(will rename if the PR number differs).