Skip to content

Commit

Permalink
Fix for n=1 case with create_using
Browse files Browse the repository at this point in the history
  • Loading branch information
Erotemic committed Nov 15, 2020
1 parent d898943 commit 39fd7d5
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions networkx/generators/trees.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,10 @@ def random_tree(n, seed=None, create_using=None):
raise nx.NetworkXPointlessConcept("the null graph is not a tree")
# Cannot create a Prüfer sequence unless `n` is at least two.
if n == 1:
return nx.empty_graph(1)

sequence = [seed.choice(range(n)) for i in range(n - 2)]
utree = nx.from_prufer_sequence(sequence)
utree = nx.empty_graph(1)
else:
sequence = [seed.choice(range(n)) for i in range(n - 2)]
utree = nx.from_prufer_sequence(sequence)

if create_using is None:
tree = utree
Expand Down

0 comments on commit 39fd7d5

Please sign in to comment.