Skip to content

fix: copy size array before reorder in multi-color scatter plots#4040

Open
Ekin-Kahraman wants to merge 2 commits intoscverse:mainfrom
Ekin-Kahraman:fix/size-array-reorder-4024
Open

fix: copy size array before reorder in multi-color scatter plots#4040
Ekin-Kahraman wants to merge 2 commits intoscverse:mainfrom
Ekin-Kahraman:fix/size-array-reorder-4024

Conversation

@Ekin-Kahraman
Copy link
Copy Markdown
Contributor

Summary

Fixes #4024.

  • Root cause: In embedding(), the per-point size array 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.
  • Fix: Use a loop-local variable _size so each iteration reorders from the original size array. This matches the behavior of color_source_vector, color_vector, and coords, which are all freshly derived each iteration.

Changes

  • src/scanpy/plotting/_tools/scatterplots.py: Replace in-place mutation of size with a loop-local _size variable; update all downstream references within the loop body.
  • tests/test_plotting.py: Add test_scatter_size_not_mutated_across_panels regression test that verifies the input size array is not modified after plotting with multiple color keys.

Test plan

  • test_scatter_size_not_mutated_across_panels passes — confirms the size array is preserved
  • Existing scatter/embedding tests continue to pass (no behavioral change for single-panel plots or scalar sizes)

Ekin-Kahraman and others added 2 commits April 8, 2026 02:22
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>
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.51%. Comparing base (9bc2c1e) to head (0d33cf7).
✅ All tests successful. No failed tests found.

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              
Flag Coverage Δ
hatch-test.low-vers 77.80% <100.00%> (-0.01%) ⬇️
hatch-test.pre 77.47% <100.00%> (+12.63%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/scanpy/plotting/_tools/scatterplots.py 83.48% <100.00%> (-0.04%) ⬇️

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.

Per-point size array is cumulatively reordered across multi-color subplots

1 participant