From 6a17c28054d57756f37f086667defbbf1b1c0c95 Mon Sep 17 00:00:00 2001 From: Ram Rachum Date: Sun, 5 Jul 2020 20:19:50 +0300 Subject: Fix exception causes and messages all over the codebase (#4015) --- networkx/relabel.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'networkx/relabel.py') diff --git a/networkx/relabel.py b/networkx/relabel.py index 8bd954b4..737b5af3 100644 --- a/networkx/relabel.py +++ b/networkx/relabel.py @@ -103,11 +103,11 @@ def _relabel_inplace(G, mapping): D.remove_edges_from(nx.selfloop_edges(D)) try: nodes = reversed(list(nx.topological_sort(D))) - except nx.NetworkXUnfeasible: + except nx.NetworkXUnfeasible as e: raise nx.NetworkXUnfeasible( "The node label sets are overlapping and no ordering can " "resolve the mapping. Use copy=True." - ) + ) from e else: # non-overlapping label sets nodes = old_labels @@ -124,8 +124,8 @@ def _relabel_inplace(G, mapping): continue try: G.add_node(new, **G.nodes[old]) - except KeyError: - raise KeyError(f"Node {old} is not in the graph") + except KeyError as e: + raise KeyError(f"Node {old} is not in the graph") from e if multigraph: new_edges = [ (new, new if old == target else target, key, data) -- cgit v1.2.1