Repository navigation
Bugfix for spring layouts with empty list of fixed nodes - #8446
Merged
Merged
Conversation
Contributor
|
Thanks, can you show the error you are seeing? +1 on the unit test! |
Contributor
Author
|
No problem and thanks for the quick reply.
The error is numpy trying to use the fixed array to index delta_pos and thinking the dtype is neither int nor bool.
It happens when arrays are initialised without a dtype (like in the current code) and numpy cannot guess the dtype (because the array is empty), so it defauls to object.
Which file would the unit test go into?
…On Mon, Jan 5, 2026, at 12:02, Alejandro Candioti wrote:
*amcandio* left a comment (networkx/networkx#8446)
<#8446 (comment)>
Thanks, can you show the error you are seeing? +1 on the unit test!
—
Reply to this email directly, view it on GitHub
<#8446 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJFEACXTKHUJNGADNP2G6T4FGZZNAVCNFSM6AAAAACQVRTUZ2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTOMBYGYYTQMRZHE>.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Contributor
Contributor
Author
|
Cheers, will add in a couple hours
…On Mon, Jan 5, 2026, at 12:47, Alejandro Candioti wrote:
*amcandio* left a comment (networkx/networkx#8446)
<#8446 (comment)>
https://github.com/networkx/networkx/blob/main/networkx/drawing/tests/test_layout.py
here seems like the best candidate
—
Reply to this email directly, view it on GitHub
<#8446 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJFEAE3EPJR4HLMQ6RTS5T4FG7DRAVCNFSM6AAAAACQVRTUZ2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTOMBYGY3TMNJXGQ>.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Contributor
Author
|
I added a unit test for this one case, should be ready for merging now |
rossbar
approved these changes
Jan 5, 2026
rossbar
left a comment
Contributor
There was a problem hiding this comment.
Nice corner case! Thanks @iosonofabio and @amcandio !
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.
Thanks for maintaining this awesome library!
Spring layout accepts a list of "fixed" nodes that won't move from (required) initial positions.
If that list is empty (an edge but acceptable case), networkx currently freaks out. This PR fixes the bug by telling numpy, which is used to create the array of fixed node indices, that this array is of type int no matter whether it's empty or not.
I found this while testing ilayoutx since I'm covering these cases there. Similar edge cases might be found in other layout functions, but that's untested for now.
Do you want me to add some kind of unit test for this?