summaryrefslogtreecommitdiff
path: root/networkx
diff options
context:
space:
mode:
authorPurvi Chaurasia <97350598+PurviChaurasia@users.noreply.github.com>2023-03-21 14:21:00 +0530
committerGitHub <noreply@github.com>2023-03-21 14:21:00 +0530
commit126a06c6315d9bcbc3b939d87f1764f77ed00cd8 (patch)
tree71b390f947fa1c02f5aca49c54955b67f3a1fee8 /networkx
parent0a114ae30bece92b80880d99fe156ce418796d5d (diff)
downloadnetworkx-126a06c6315d9bcbc3b939d87f1764f77ed00cd8.tar.gz
Fixed bug k_truss doesn't raise exception for self loops (#6521)
* Fix negative edge cycle function raising exception for empty graph and added relevant test function * Fixed k_truss doesn't raise exception for self loops * conflicts resolved
Diffstat (limited to 'networkx')
-rw-r--r--networkx/algorithms/core.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/networkx/algorithms/core.py b/networkx/algorithms/core.py
index 22e1a8d5..0ec1a446 100644
--- a/networkx/algorithms/core.py
+++ b/networkx/algorithms/core.py
@@ -392,8 +392,8 @@ def k_truss(G, k):
------
NetworkXError
- The k-truss is not defined for graphs with self loops or parallel edges
- or directed graphs.
+ The k-truss is not defined for graphs with self loops, directed graphs
+ and multigraphs.
Notes
-----
@@ -416,6 +416,13 @@ def k_truss(G, k):
.. [2] Trusses: Cohesive Subgraphs for Social Network Analysis. Jonathan
Cohen, 2005.
"""
+ if nx.number_of_selfloops(G) > 0:
+ msg = (
+ "Input graph has self loops which is not permitted; "
+ "Consider using G.remove_edges_from(nx.selfloop_edges(G))."
+ )
+ raise NetworkXError(msg)
+
H = G.copy()
n_dropped = 1