Fix KDTree scalar return when max_num_neighbours=1#90
Open
Aadrit555 wants to merge 10 commits intomllam:mainfrom
Open
Fix KDTree scalar return when max_num_neighbours=1#90Aadrit555 wants to merge 10 commits intomllam:mainfrom
Aadrit555 wants to merge 10 commits intomllam:mainfrom
Conversation
leifdenby
requested changes
Mar 6, 2026
Member
leifdenby
left a comment
There was a problem hiding this comment.
Looking good. Please add a changelog entry :)
Author
|
@leifdenby did it can you check please, thanks. |
Member
|
Can you fix the linting errors please? Just run pre-commit locally before re-committing |
Author
|
@leifdenby Sorry for the messy commits — being fairly new to open source I got a bit confused while trying to fix the linting errors. I've got all pre-commit checks passing locally now. I tried to squash the commits via rebase but would need your help to do that since I don't have the required permissions. Happy to clean it up however works best for you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes made -
I fixed a crash in
connect_nodes_across_graphswhen called withmethod="nearest_neighbours"andmax_num_neighbours=1.Root cause:
scipy.spatial.KDTree.query()returns different types depending on the value ofk:k = 1→ scalar (numpy.int64)k > 1→numpy.ndarrayThe function
_find_neighbour_node_idxs_in_source_meshreturned the raw query result, which the caller then iterated over. Whenk=1, iterating over a scalar raises:Fix: Wrap the return value with
np.atleast_1d()so the result is always iterable, regardless ofk.No dependencies are required for this change.
Issue Link
Closes #83
Type of change
Checklist before requesting a review
pullwith--rebaseoption if possible).Checklist for reviewers
Each PR comes with its own improvements and flaws. The reviewer should check the following:
Author checklist after completed review
reflecting type of change (add section where missing):
connect_nodes_across_graphscrash whenmax_num_neighbours=1due toKDTree.queryreturning a scalar fork=1Checklist for assignee