fix: copy size array before reorder in multi-color scatter plots#4040
Open
Ekin-Kahraman wants to merge 2 commits intoscverse:mainfrom
Open
fix: copy size array before reorder in multi-color scatter plots#4040Ekin-Kahraman wants to merge 2 commits intoscverse:mainfrom
Ekin-Kahraman wants to merge 2 commits intoscverse:mainfrom
Conversation
When plotting with multiple color keys and a per-point size array, the size variable was reordered in-place within the per-color loop. Each subsequent subplot applied its z-order permutation to the already-reordered array from the previous iteration, causing cumulative corruption of marker sizes. Use a loop-local variable `_size` so each iteration reorders from the original array. Closes scverse#4024 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
for more information, see https://pre-commit.ci
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4040 +/- ##
==========================================
- Coverage 78.51% 78.51% -0.01%
==========================================
Files 117 117
Lines 12753 12752 -1
==========================================
- Hits 10013 10012 -1
Misses 2740 2740
Flags with carried forward coverage won't be shown. Click here to find out more.
|
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
Fixes #4024.
embedding(), the per-pointsizearray was reordered in-place (size = np.array(size)[order]) inside the per-color loop. Each iteration's z-order permutation was applied to the already-reordered array from the previous iteration, causing cumulative corruption of marker sizes across subplots._sizeso each iteration reorders from the originalsizearray. This matches the behavior ofcolor_source_vector,color_vector, andcoords, which are all freshly derived each iteration.Changes
src/scanpy/plotting/_tools/scatterplots.py: Replace in-place mutation ofsizewith a loop-local_sizevariable; update all downstream references within the loop body.tests/test_plotting.py: Addtest_scatter_size_not_mutated_across_panelsregression test that verifies the input size array is not modified after plotting with multiple color keys.Test plan
test_scatter_size_not_mutated_across_panelspasses — confirms the size array is preserved