Skip to content

spatial_neigbours extensibility features and clarification#1147

Open
selmanozleyen wants to merge 78 commits into
scverse:mainfrom
selmanozleyen:feat/spatial_neighbours
Open

spatial_neigbours extensibility features and clarification#1147
selmanozleyen wants to merge 78 commits into
scverse:mainfrom
selmanozleyen:feat/spatial_neighbours

Conversation

@selmanozleyen
Copy link
Copy Markdown
Member

@selmanozleyen selmanozleyen commented Apr 2, 2026

fixes: #1102 and #1047

It's backward compatible and I am curious what the community might bring to this!

  • I clarified the docs on argument precedence
  • Added extensibility features
  • Added tests to ensure the function behaves as written in the docs
  • No breaking changes

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 2, 2026

Codecov Report

❌ Patch coverage is 87.90323% with 45 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.12%. Comparing base (67b2c74) to head (0ed1604).

Files with missing lines Patch % Lines
src/squidpy/gr/_build.py 80.55% 24 Missing and 4 partials ⚠️
src/squidpy/gr/neighbors.py 92.44% 11 Missing and 6 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1147      +/-   ##
==========================================
+ Coverage   73.82%   74.12%   +0.30%     
==========================================
  Files          45       46       +1     
  Lines        7013     7195     +182     
  Branches     1188     1193       +5     
==========================================
+ Hits         5177     5333     +156     
- Misses       1349     1371      +22     
- Partials      487      491       +4     
Files with missing lines Coverage Δ
src/squidpy/_docs.py 94.44% <100.00%> (+0.24%) ⬆️
src/squidpy/gr/neighbors.py 92.44% <92.44%> (ø)
src/squidpy/gr/_build.py 81.31% <80.55%> (-7.22%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@selmanozleyen selmanozleyen requested a review from grst April 2, 2026 12:30
@selmanozleyen selmanozleyen requested a review from timtreis April 2, 2026 12:53
@selmanozleyen selmanozleyen self-assigned this Apr 2, 2026
Copy link
Copy Markdown
Contributor

@grst grst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @selmanozleyen, that goes in the right direction. I put up some design questions up for discussion!

Comment thread src/squidpy/gr/_build.py Outdated
Comment thread src/squidpy/gr/_build.py
Comment thread src/squidpy/gr/neighbors.py Outdated
Comment thread src/squidpy/gr/neighbors.py Outdated
Comment thread src/squidpy/gr/neighbors.py Outdated
Comment thread src/squidpy/gr/neighbors.py Outdated
Comment thread src/squidpy/gr/neighbors.py Outdated
Comment thread src/squidpy/gr/neighbors.py Outdated
@selmanozleyen selmanozleyen requested a review from timtreis April 13, 2026 22:33
Copy link
Copy Markdown

@shashkat shashkat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks amazing to me now! Just a few more minor suggestions. I really liked the idea of using specialized Postprocessor classes!

Comment thread src/squidpy/gr/_build.py Outdated
Comment thread src/squidpy/gr/neighbors.py
Comment thread src/squidpy/gr/neighbors.py
Comment thread src/squidpy/gr/neighbors.py Outdated
Comment thread src/squidpy/gr/neighbors.py
@selmanozleyen
Copy link
Copy Markdown
Member Author

These classes would be also ideally serializable so we dont need to rely on a forman under adata.uns which we are scared to change. I will make this as an issue to tackle when the time comes

Copy link
Copy Markdown
Member

@timtreis timtreis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're not really explicitly testing the new pattern, just indirectly through the equvialence tests.

Also, we should align on the deprecate warning version

Claude:

Extensibility doc: SNN example will not import / run as written

  docs/extensibility.md SNNRadiusBuilder.build_graph doesn't initialise the matrices' set_diag consistently with the rest of the codebase — adj.setdiag(1.0 if self.set_diag else adj.diagonal()) will materialise an explicit zero diagonal because
  csr_matrix.diagonal() of a freshly constructed matrix returns a dense vector of zeros, then setdiag(0.0) is set on dst (fine). Minor, but worth either (a) testing this snippet in CI as a doctest, or (b) simplifying to mirror what
  RadiusBuilder.build_graph actually does. Also the example imports snnpy (optional 3p dep) and silently breaks doc-build if anyone runs the snippet — flag clearly that it is illustrative.

Comment thread src/squidpy/gr/_build.py Outdated
Comment thread src/squidpy/gr/_build.py Outdated
"connectivities_key": conns_key,
"distances_key": dists_key,
"params": {
"n_neighbors": getattr(builder, "n_neighs", 6),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is 6 hardcoded? Not all method have 6 neighbors

Comment thread src/squidpy/gr/_build.py Outdated
elements_to_coordinate_systems: dict[str, str] | None = None,
table_key: str | None = None,
library_key: str | None = None,
radius: float | tuple[float, float] = 1.0,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the default of 1 here? Isn't it None in the others?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right, I made it a non-defaulted positional arg

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, it's also possible to have keyword-only arguments without default.

Comment thread src/squidpy/gr/_build.py Outdated
elements_to_coordinate_systems: dict[str, str] | None = None,
table_key: str | None = None,
library_key: str | None = None,
n_neighs: Literal[4, 6] = 6,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 4, 6 as a Literal?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the docs what I understood is only those two makes sense

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oky I fixed it

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.

Documentation for sq.gr.spatial_neighbors() likely needs more clarification about the interplay of arguments

4 participants