Skip to content

Commit

Permalink
Add @not_implemented_for("directed") to `number_connected_component…
Browse files Browse the repository at this point in the history
…s` (networkx#7074)

Previously, it was relying on a call to `connected_components` to check
the graph type, but this doesn't work well when dispatching to a backend.
Also, fix an exception message.
  • Loading branch information
eriknw authored and cvanelteren committed Apr 22, 2024
1 parent 3aa78e1 commit 215660f
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion networkx/algorithms/components/connected.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def connected_components(G):
yield c


@not_implemented_for("directed")
@nx._dispatch
def number_connected_components(G):
"""Returns the number of connected components.
Expand Down Expand Up @@ -143,7 +144,7 @@ def is_connected(G):
"""
if len(G) == 0:
raise nx.NetworkXPointlessConcept(
"Connectivity is undefined ", "for the null graph."
"Connectivity is undefined for the null graph."
)
return sum(1 for node in _plain_bfs(G, arbitrary_element(G))) == len(G)

Expand Down

0 comments on commit 215660f

Please sign in to comment.