Closed KubaWernerowski closed 2 years ago
Hi @KubaWernerowski , thanks for your question. Please note that igraph
uses integer representations for graphs, while networkx
just uses any object. In this case, the networkx
graph G
happens to use integers as well, but this is not necessary. During the conversion in ig.Graph.from_networkx(G)
every node from G
is assigned an integer index, which in this case, does not coincide with the integer label from G
itself. Unfortunately, it is not possible for igraph
to guarantee that the integer index matches the integer label from networkx
, because in general, it can simply be any Python object in networkx
. The original labels from networkx
are stored as a vertex attribute called _nx_name
in igraph
:
>>> G_ig.vs['_nx_name']
[0, 1, 2, 3, 4, 6, 7, 8, 9, 10, 5]
Note that in this case the nodes are indeed not ordered according to the original networkx
labels.
You can see the original labels of the first community as
>>> G_ig.vs[partition[0]]['_nx_name']
[0, 1, 2, 3, 4, 5]
Simply plotting both partition
and partition2
shows that indeed the clusters are as expected (and connected):
ig.plot(partition)
ig.plot(partition2)
I assume this solves your problem, so I'll close the issue for now. If you do have another question, feel free to re-open this issue (or open a new issue if it's about something else).
Hi @vtraag, thank you for the quick response, and the detailed explanation of what was going on; I really appreciate it, thank you!
Hi @vtraag I think this is a possible bug, since Leiden is supposed to guarantee that communities are not internally disconnected.
python version: 3.8.2
leidenalg version: 0.8.8
igraph version: 0.9.9
networkx version: 2.5.1
Code to reproduce:
Given this graph, it seems that when using
ModularityVertexPartition
, nodes4
and10
are in the same community, but their community is internally disconnected.