GiulioRossetti / cdlib

Community Discovery Library
http://cdlib.readthedocs.io
BSD 2-Clause "Simplified" License
367 stars 71 forks source link

`utils.__from_nx_to_igraph` breaks when isolated nodes are present #227

Closed bgleaso1 closed 4 months ago

bgleaso1 commented 11 months ago

Describe the bug

Conversion from nx.Graph to ig.Graph in utils.__from_nx_to_igraph breaks when there are isolates (nodes without edges) present. It throws the following error:

networkx.exception.AmbiguousSolution: Disconnected graph: Ambiguous solution for bipartite sets.

To Reproduce

Steps to reproduce the behavior:

import cdlib
import networkx as nx
from cdlib import utils

_g = nx.Graph({
    '5013469205': {},
    '5012920363': {'5012920217': {}},
    '5012920217': {'5012920363': {}},
    '5012920377': {'5013279789': {}},
    '5012920753': {'5013279789': {}},
    '5013279789': {'5012920377': {}, '5012920753': {}},
    '1001352506': {'5001229487': {}},
    '5001229487': {'1001352506': {}}
})
utils.__from_nx_to_igraph(_g)

Expected behavior Conversion to igraph.Graph should succeed, error free.