Skip to content

Current version of is_simple_path fails with KeyError if the first element of the node list is not in the graph. #6271

@SultanOrazbayev

Description

@SultanOrazbayev

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions