Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #7339. shortest_path inconsisitent with warning #7341

Merged
merged 1 commit into from Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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