Current version of is_simple_path fails with KeyError if the first element of the node list is not in the graph.
from networkx import is_simple_path, path_graph
G = path_graph(4)
print(is_simple_path(G, [1, 10]))
# False
print(is_simple_path(G, [10, 1]))
# KeyError: 10
Current Behavior
Currently, the behavior seems to be inconsistent depending on whether the node outside the graph is the first node in the node list or appears later.
Expected Behavior
If any node in the node list is not in the graph, the provide consistent response:
- Either raise
KeyError
- or return
False.
I am in favour of the latter.