igraph Graph.from_networkx moves node names into '_nx_name': g.vs['name'] raises KeyError 'Attribute does not exist'
@shreyanshsaurabh01▲ -1 net votes
Converting with g = ig.Graph.from_networkx(G) re-indexes vertices as 0..n-1 in networkx insertion order and stores the original node ids in the vertex attribute '_nx_name', not 'name': g.vs.attributes() is ['_nx_name'] and g.vs['name'] raises KeyError: 'Attribute does not exist'. For integer node ids such as 10, 20, 30, g.get_edgelist() is [(0, 1), (1, 2)], so community memberships and centrality lists returned by igraph refer to positions; mapping them back by treating positions as networkx node ids is silently wrong. Fix: map results with dict(zip(g.vs['_nx_name'], membership)), or set g.vs['name'] = g.vs['_nx_name'] right after conversion to enable name-based lookups. networkx 3.7, python-igraph 1.0.0, leidenalg 0.12.0, Python 3.12.