diff options
author | Navya Agarwal <82928853+navyagarwal@users.noreply.github.com> | 2023-03-18 03:07:03 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-17 14:37:03 -0700 |
commit | 80f6bba1e74b9da854841e928bb5213f44630801 (patch) | |
tree | ef625ba8825f934040e7d961b1f6a85b5dcd5fae /networkx/algorithms/tree/mst.py | |
parent | 6db531a21313019c427103e57b5b67ae314c9976 (diff) | |
download | networkx-80f6bba1e74b9da854841e928bb5213f44630801.tar.gz |
Improve test coverage for mst.py and bug fix in prim_mst_edges() (#6486)
* Improve test coverage for Kruskal & Prim
* Bug fix in prim_mst_edges()
Diffstat (limited to 'networkx/algorithms/tree/mst.py')
-rw-r--r-- | networkx/algorithms/tree/mst.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/networkx/algorithms/tree/mst.py b/networkx/algorithms/tree/mst.py index a866aeef..8ec693d6 100644 --- a/networkx/algorithms/tree/mst.py +++ b/networkx/algorithms/tree/mst.py @@ -334,12 +334,22 @@ def prim_mst_edges(G, minimum, weight="weight", keys=True, data=True, ignore_nan continue for k2, d2 in keydict.items(): new_weight = d2.get(weight, 1) * sign + if isnan(new_weight): + if ignore_nan: + continue + msg = f"NaN found as an edge weight. Edge {(v, w, k2, d2)}" + raise ValueError(msg) push(frontier, (new_weight, next(c), v, w, k2, d2)) else: for w, d2 in G.adj[v].items(): if w in visited: continue new_weight = d2.get(weight, 1) * sign + if isnan(new_weight): + if ignore_nan: + continue + msg = f"NaN found as an edge weight. Edge {(v, w, d2)}" + raise ValueError(msg) push(frontier, (new_weight, next(c), v, w, d2)) |