Skip to content

Commit

Permalink
Fix networkx#7339. shortest_path inconsisitent with warning
Browse files Browse the repository at this point in the history
  • Loading branch information
eriknw committed Mar 11, 2024
1 parent ef5f9ac commit 72905b6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion networkx/algorithms/centrality/reaching.py
Expand Up @@ -112,7 +112,7 @@ def as_distance(u, v, d):
# TODO This can be trivially parallelized.
lrc = [
centrality(G, node, paths=paths, weight=weight, normalized=normalized)
for node, paths in shortest_paths
for node, paths in shortest_paths.items()
]

max_lrc = max(lrc)
Expand Down
6 changes: 3 additions & 3 deletions networkx/algorithms/shortest_paths/generic.py
Expand Up @@ -149,11 +149,11 @@ def shortest_path(G, source=None, target=None, weight=None, method="dijkstra"):

# Find paths between all pairs.
if method == "unweighted":
paths = nx.all_pairs_shortest_path(G)
paths = dict(nx.all_pairs_shortest_path(G))
elif method == "dijkstra":
paths = nx.all_pairs_dijkstra_path(G, weight=weight)
paths = dict(nx.all_pairs_dijkstra_path(G, weight=weight))
else: # method == 'bellman-ford':
paths = nx.all_pairs_bellman_ford_path(G, weight=weight)
paths = dict(nx.all_pairs_bellman_ford_path(G, weight=weight))
else:
# Find paths from all nodes co-accessible to the target.
if G.is_directed():
Expand Down
4 changes: 3 additions & 1 deletion networkx/algorithms/shortest_paths/tests/test_generic.py
Expand Up @@ -212,7 +212,9 @@ def test_single_source_all_shortest_paths(self):
assert sorted(ans[4]) == [[4]]

def test_all_pairs_shortest_path(self):
p = dict(nx.shortest_path(self.cycle))
# shortest_path w/o source and target will return a generator instead of
# a dict beginning in version 3.5. Only the first call needs changed here.
p = nx.shortest_path(self.cycle)
assert p[0][3] == [0, 1, 2, 3]
assert p == dict(nx.all_pairs_shortest_path(self.cycle))
p = dict(nx.shortest_path(self.grid))
Expand Down

0 comments on commit 72905b6

Please sign in to comment.