Update simple_paths.py: consistent behaviour for is_simple_path when path contains nodes not in the graph.#6272
Merged
dschult merged 9 commits intonetworkx:mainfrom Dec 20, 2022
Conversation
Current version of `is_simple_path` fails with `KeyError` if the first element of the node list is not in the graph.
Simplify the test condition. Checking for a single node in the list can be combined with checking for duplicates in the list without meaningful efficiency loss.
Add the case when the start of the path is a node not in the graph.
is_simple_path when path contains nodes not in the graph.
rossbar
reviewed
Dec 13, 2022
Contributor
rossbar
left a comment
There was a problem hiding this comment.
+1 on the test, but it seems like there are more proposed changes than necessary - isn't all that's needed is to add the if not all(n in G for n in nodes) check? It could just be that I'm reading the diff wrong!
Contributor
Author
|
You're right, @rossbar , the simplified code is more readable also. |
Contributor
Author
|
OK, tests are failing due to this: import networkx as nx
G = nx.trivial_graph()
print(all(n in G for n in [])) # True |
Still need to check the special case of a list with 1 item.
dschult
approved these changes
Dec 20, 2022
MridulS
pushed a commit
to MridulS/networkx
that referenced
this pull request
Feb 4, 2023
…n path contains nodes not in the graph. (networkx#6272) * Update simple_paths.py Current version of `is_simple_path` fails with `KeyError` if the first element of the node list is not in the graph. * Update simple_paths.py * Update simple_paths.py Simplify the test condition. Checking for a single node in the list can be combined with checking for duplicates in the list without meaningful efficiency loss. * Update test_simple_paths.py Add the case when the start of the path is a node not in the graph. * Update simple_paths.py * Update simple_paths.py * Update simple_paths.py * Update simple_paths.py * Update simple_paths.py Still need to check the special case of a list with 1 item.
cvanelteren
pushed a commit
to cvanelteren/networkx
that referenced
this pull request
Apr 22, 2024
…n path contains nodes not in the graph. (networkx#6272) * Update simple_paths.py Current version of `is_simple_path` fails with `KeyError` if the first element of the node list is not in the graph. * Update simple_paths.py * Update simple_paths.py Simplify the test condition. Checking for a single node in the list can be combined with checking for duplicates in the list without meaningful efficiency loss. * Update test_simple_paths.py Add the case when the start of the path is a node not in the graph. * Update simple_paths.py * Update simple_paths.py * Update simple_paths.py * Update simple_paths.py * Update simple_paths.py Still need to check the special case of a list with 1 item.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Current version of
is_simple_pathfails withKeyErrorif the first element of the node list is not in the graph.Resolves #6271, by returning
Falseif any node in the provided path is outside the graph.