Skip to content

feat: allow precomputed connectivities in neighbors#4133

Draft
ehsanestaji wants to merge 3 commits into
scverse:mainfrom
ehsanestaji:feat/2157-precomputed-distance-umap
Draft

feat: allow precomputed connectivities in neighbors#4133
ehsanestaji wants to merge 3 commits into
scverse:mainfrom
ehsanestaji:feat/2157-precomputed-distance-umap

Conversation

@ehsanestaji
Copy link
Copy Markdown

Summary

This adds a connectivities argument to sc.pp.neighbors, allowing callers to provide an externally computed neighborhood graph directly. The graph is stored in .obsp and can be consumed by downstream graph-based tools such as sc.tl.umap without requiring Scanpy to recompute neighbors from adata.

When both distances and connectivities are provided, Scanpy stores the supplied distances alongside the supplied connectivities. When only connectivities is provided, no distances matrix is written.

Testing

  • uv run --group test-min pytest tests/test_neighbors.py tests/test_neighbors_key_added.py -q
  • uv run --group test-min ruff check src/scanpy/neighbors/__init__.py tests/test_neighbors.py
  • uv run --group test-min ruff format --check src/scanpy/neighbors/__init__.py tests/test_neighbors.py
  • git diff --check

@ehsanestaji ehsanestaji changed the title Allow precomputed connectivities in neighbors feat: allow precomputed connectivities in neighbors May 19, 2026
@ehsanestaji
Copy link
Copy Markdown
Author

Thanks for maintaining Scanpy. The PR validation asks for either a milestone or the no milestone label. I do not have permission to set labels on this repository, so could a maintainer please add the appropriate milestone/label when you have a moment?

@codecov
Copy link
Copy Markdown

codecov Bot commented May 19, 2026

Codecov Report

❌ Patch coverage is 97.05882% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 79.70%. Comparing base (6bfd839) to head (8f7731d).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/scanpy/neighbors/__init__.py 97.05% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4133      +/-   ##
==========================================
+ Coverage   79.61%   79.70%   +0.09%     
==========================================
  Files         120      120              
  Lines       12786    12805      +19     
==========================================
+ Hits        10179    10206      +27     
+ Misses       2607     2599       -8     
Flag Coverage Δ
hatch-test.low-vers 78.94% <97.05%> (+0.08%) ⬆️
hatch-test.pre 79.56% <97.05%> (+0.08%) ⬆️

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

Files with missing lines Coverage Δ
src/scanpy/neighbors/__init__.py 84.52% <97.05%> (+2.47%) ⬆️

... and 1 file with indirect coverage changes

@Zethson Zethson added this to the 1.12.2 milestone May 21, 2026
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.

Compute UMAP from pre-existing distance matrix

2 participants