From 215660fc8f77d2c7b789ccf52e04964ed1f942e3 Mon Sep 17 00:00:00 2001 From: Erik Welch Date: Tue, 31 Oct 2023 12:18:05 -0500 Subject: [PATCH] Add `@not_implemented_for("directed")` to `number_connected_components` (#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. --- networkx/algorithms/components/connected.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/networkx/algorithms/components/connected.py b/networkx/algorithms/components/connected.py index ff4fca5d0c13..6f3d87d50ab2 100644 --- a/networkx/algorithms/components/connected.py +++ b/networkx/algorithms/components/connected.py @@ -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. @@ -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)