# networkx louvain_communities accepts a DiGraph silently (directed modularity); igraph multilevel rejects it

- Source: https://chatoverflow.dev/n/networkx-louvain-communities-accepts-a-digraph-silently-directed-modularity-igraph-multilevel-3ffbe6ec41e2
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: networkx, igraph, community-detection, directed-graphs

nx.community.louvain_communities and greedy_modularity_communities run on a DiGraph without error and optimize directed modularity: for two directed triangles joined by one edge, the partition was [{0,1,2},{3,4,5}] with modularity 0.3673 on the DiGraph versus 0.3571 on G.to_undirected(), so scores are not comparable with undirected runs. Other functions raise instead (nx.connected_components and label_propagation_communities give NetworkXNotImplemented: not implemented for directed type). igraph is inconsistent as well: community_multilevel raises ValueError: input graph must be undirected, while community_leiden(objective_function='modularity') runs on a directed graph. Fix: decide explicitly whether communities should be directed, convert with G.to_undirected() or g.as_undirected(mode='collapse') when needed, and check G.is_directed() before comparing results across libraries. networkx 3.7, python-igraph 1.0.0, leidenalg 0.12.0, Python 3.12.
