Skip to content

fix: preserve SpatialData input when copying spatial neighbors - #1292

Open
Georicl wants to merge 1 commit into
scverse:mainfrom
Georicl:fix/1154-spatial-neighbors-copy
Open

Georicl wants to merge 1 commit into
scverse:mainfrom
Georicl:fix/1154-spatial-neighbors-copy

Conversation

@Georicl

@Georicl Georicl commented Sep 14, 2026

Copy link
Copy Markdown

Description

Building spatial neighbor graphs from a SpatialData object with copy=True currently writes computed centroids into the original table before returning the graph. This can overwrite existing coordinates, add a new coordinate key, or leave changed coordinates behind when graph construction fails.

Pass copy through the shared input preparation path and use a temporary AnnData containing observation metadata and the metadata needed for legacy graph dispatch. This keeps computed coordinates out of the original table without copying or loading expression matrices, including for backed tables. The change covers the legacy function and all five current graph-building entry points. copy=False retains its existing behavior.

How has this been tested?

  • 91 tests passed across tests/graph/test_spatial_neighbors_copy.py and the existing tests/graph/test_spatial_neighbors.py on Python 3.13/macOS.
  • The initial 28 regression cases failed against upstream before the fix.
  • Coverage includes existing and missing coordinates, default and custom spatial keys, construction failures, read-only backed tables and unchanged files on disk, all six entry points, and multiple libraries. Returned graphs are compared with the in-place path.
  • All applicable repository pre-commit checks and git diff --check passed.
  • Full Sphinx HTML build passed with warnings treated as errors (-W); verified the generated release note.

Closes

Closes #1154

@codecov

codecov Bot commented Sep 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.46%. Comparing base (8286274) to head (5a07857).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1292      +/-   ##
==========================================
+ Coverage   78.44%   78.46%   +0.02%     
==========================================
  Files          63       63              
  Lines        9532     9533       +1     
  Branches     1594     1594              
==========================================
+ Hits         7477     7480       +3     
+ Misses       1489     1488       -1     
+ Partials      566      565       -1     
Files with missing lines Coverage Δ
src/squidpy/gr/_build.py 90.54% <100.00%> (+0.09%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

spatial_neighbors unintended in-place change

1 participant