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

Fix random_spanning_tree() for single node and empty graphs #7211

Conversation

nihalgeorge01
Copy link
Contributor

@nihalgeorge01 nihalgeorge01 commented Jan 7, 2024

Partial fix for issue #6920 for random_spanning_tree() by checking explicitly for empty and single node graphs. Earlier, the main for loop was the only return path, and these edge cases would cause an Exception meant for trees with less edges.

@nihalgeorge01 nihalgeorge01 changed the title Fix random spanning tree single node and empty graph Fix random_spanning_tree() for single node and empty graphs Jan 7, 2024
Copy link
Member

@dschult dschult left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be done in a more compact way. Probably the tests too, but not as important. I suggest another test below also.

networkx/algorithms/tree/mst.py Outdated Show resolved Hide resolved
networkx/algorithms/tree/tests/test_mst.py Outdated Show resolved Hide resolved
networkx/algorithms/tree/mst.py Outdated Show resolved Hide resolved
networkx/algorithms/tree/mst.py Outdated Show resolved Hide resolved
Copy link
Member

@dschult dschult left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this!

Copy link
Contributor

@rossbar rossbar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @nihalgeorge01 , and @Schefflera-Arboricola and @dschult for review!

@rossbar rossbar merged commit 54eca15 into networkx:main Jan 11, 2024
39 checks passed
@jarrodmillman jarrodmillman added this to the 3.3 milestone Jan 11, 2024
cvanelteren pushed a commit to cvanelteren/networkx that referenced this pull request Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

5 participants