Skip to content

spatial_neigbours extensibility features and clarification#1147

Open
selmanozleyen wants to merge 47 commits intoscverse:mainfrom
selmanozleyen:feat/spatial_neighbours
Open

spatial_neigbours extensibility features and clarification#1147
selmanozleyen wants to merge 47 commits intoscverse: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.35632% with 44 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.31%. Comparing base (76ca03f) to head (95012dc).

Files with missing lines Patch % Lines
src/squidpy/gr/_build.py 79.85% 24 Missing and 4 partials ⚠️
src/squidpy/gr/neighbors.py 92.23% 12 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1147      +/-   ##
==========================================
+ Coverage   74.05%   74.31%   +0.25%     
==========================================
  Files          39       40       +1     
  Lines        6495     6658     +163     
  Branches     1122     1123       +1     
==========================================
+ Hits         4810     4948     +138     
- Misses       1230     1253      +23     
- Partials      455      457       +2     
Files with missing lines Coverage Δ
src/squidpy/_docs.py 94.44% <100.00%> (+0.24%) ⬆️
src/squidpy/gr/neighbors.py 92.23% <92.23%> (ø)
src/squidpy/gr/_build.py 81.31% <79.85%> (-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!

@selmanozleyen selmanozleyen requested a review from grst April 2, 2026 17:02
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.

Thanks a lot for doing this :)
Here are some minor suggestions from me!

def build_graph(self, coords: NDArrayA) -> tuple[csr_matrix, csr_matrix]:
N = coords.shape[0]
r = self.radius if isinstance(self.radius, int | float) else max(self.radius)
tree = NearestNeighbors(n_neighbors=self.n_neighs, radius=r, metric="euclidean")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since we are using tree.radius_neighbors() below, is the n_neighbors = self.n_neighs having an effect here?
Is it intentional to have some of these arguments still valid for RadiusBuilder, DelaunayBuilder etc? I see that for the parameter n_neighs, there is a warning in DelaunayBuilder that it will be ignored. If its intentional to keep these arguments for now, then possibly can add warning for n_neighs in RadiusBuilder too.

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 it was a legacy thing. I removed it now

"transform": transform,
"set_diag": set_diag,
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

WRT the removal of non necessary arguments from RadiusBuilder, DelaunayBuilder etc, whenever it is decided to remove them (now or later), it would also be nice to make the logic here more explicit. By more explicit logic I mean if else hierarchy closely resembling the decision tree we have possible. I made a rough version according to my understanding:

Image

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.

Since all of this is deprecated anyway, I wouldn't put too much effort into making this part "nice"

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.

It's taking a nice shape now... mostly minor things at this point!

"transform": transform,
"set_diag": set_diag,
}

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.

Since all of this is deprecated anyway, I wouldn't put too much effort into making this part "nice"

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.

Only some doc suggestions left from my side.

Apart from that LGTM, I'll leave final approval to @timtreis

@selmanozleyen
Copy link
Copy Markdown
Member Author

Thanks a lot @grst ! I really appreciate your reviews. I assesed them and even made a more general class to support Cupy arrays in future.

@selmanozleyen selmanozleyen requested a review from grst April 10, 2026 13:42
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.

Love 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

3 participants