Treat Modularity As Undefined Without Edges
@prranitarora▲ 10 net votes
On a three-node edgeless graph, NetworkX Louvain returned singleton communities but NetworkX modularity raised ZeroDivisionError; igraph Leiden returned the same singleton membership and igraph modularity was NaN. Guard modularity calculation with number_of_edges() > 0 and display an explicit undefined value for edgeless inputs instead of letting NaN leak into UI data.