Skip to content

Bugfix for spring layouts with empty list of fixed nodes - #8446

Merged
rossbar merged 3 commits into
networkx:mainfrom
iosonofabio:bugfix_fixed_spring
Jan 5, 2026
Merged

rossbar merged 3 commits into
networkx:mainfrom
iosonofabio:bugfix_fixed_spring

Conversation

@iosonofabio

Copy link
Copy Markdown
Contributor

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?

@amcandio

amcandio commented Jan 5, 2026

Copy link
Copy Markdown
Contributor

Thanks, can you show the error you are seeing? +1 on the unit test!

@iosonofabio

iosonofabio commented Jan 5, 2026 via email

Copy link
Copy Markdown
Contributor Author

@amcandio

amcandio commented Jan 5, 2026

Copy link
Copy Markdown
Contributor

@iosonofabio

iosonofabio commented Jan 5, 2026 via email

Copy link
Copy Markdown
Contributor Author

@iosonofabio

Copy link
Copy Markdown
Contributor Author

I added a unit test for this one case, should be ready for merging now

@amcandio amcandio left a comment

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.

Grazie Fabio, voto 10!

@rossbar rossbar left a comment

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.

Nice corner case! Thanks @iosonofabio and @amcandio !

Comment thread networkx/drawing/tests/test_layout.py Resolved
@rossbar
rossbar merged commit 22805a7 into networkx:main Jan 5, 2026
@dschult dschult added this to the 3.7 milestone Jan 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

4 participants