Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync up behavior of is_{type} for empty graphs #5849

Merged
merged 9 commits into from
Dec 18, 2023
2 changes: 2 additions & 0 deletions networkx/algorithms/chordal.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,8 @@ def _find_chordality_breaker(G, s=None, treewidth_bound=sys.maxsize):

It ignores any self loops.
"""
if len(G) == 0:
raise nx.NetworkXPointlessConcept("Graph has no nodes.")
unnumbered = set(G)
if s is None:
s = arbitrary_element(G)
Expand Down
3 changes: 2 additions & 1 deletion networkx/algorithms/dag.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,8 @@ def is_aperiodic(G):
"""
if not G.is_directed():
raise nx.NetworkXError("is_aperiodic not defined for undirected graphs")

if len(G) == 0:
raise nx.NetworkXPointlessConcept("Graph has no nodes.")
s = arbitrary_element(G)
levels = {s: 0}
this_level = [s]
Expand Down
2 changes: 2 additions & 0 deletions networkx/algorithms/distance_regular.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ def intersection_array(G):
global_parameters
"""
# test for regular graph (all degrees must be equal)
if len(G) == 0:
raise nx.NetworkXPointlessConcept("Graph has no nodes.")
degree = iter(G.degree())
(_, k) = next(degree)
for _, knext in degree:
Expand Down
2 changes: 2 additions & 0 deletions networkx/algorithms/regular.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ def is_regular(G):
True

"""
if len(G) == 0:
raise nx.NetworkXPointlessConcept("Graph has no nodes.")
n1 = nx.utils.arbitrary_element(G)
if not G.is_directed():
d1 = G.degree(n1)
Expand Down