Skip to content

networkx g.nodes is not a list but is iterable#567

Merged
ntamas merged 4 commits intoigraph:masterfrom
iosonofabio:from_networkx_fix
Sep 9, 2022
Merged

networkx g.nodes is not a list but is iterable#567
ntamas merged 4 commits intoigraph:masterfrom
iosonofabio:from_networkx_fix

Conversation

@iosonofabio
Copy link
Copy Markdown
Member

Aiming at fixing #566.

We should add a test to this one before merging.

@ntamas
Copy link
Copy Markdown
Member

ntamas commented Sep 8, 2022

Okay, so, if I understand correctly, the purpose of that condition would be to check whether all nodes have an attribute named _igraph_index in the NetworkX graph, right? I don't think that next(iter(g.nodes)) (as suggested in this PR) would do the trick as g.nodes seems to iterate over the node names.

I think the correct fix would be next(iter(nxg.nodes.values())). This is a bit convoluted, but basically nxg.nodes returns a dict-like view that maps NetworkX node names to their "data dictionaries"; next(iter(...)) then takes the first element of it, which is the data dictionary of the first node.

@iosonofabio iosonofabio marked this pull request as ready for review September 8, 2022 19:34
@iosonofabio
Copy link
Copy Markdown
Member Author

yep... shall we squash & merge?

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.

2 participants