Repository navigation
Add check for empty graphs in non_randomness - #7395
Conversation
dschult
left a comment
There was a problem hiding this comment.
Thanks for this!
I have a suggestion for a one-liner to create the graph with 1 node.
Co-authored-by: Dan Schult <[email protected]>
rossbar
left a comment
There was a problem hiding this comment.
This one is a bit trickier than it appears: the only case that is not currently handled is when G has only one node and 0 edges. The is_connected check already handles all other graphs with no edges, so long as they have more than one node.
So, in order to be consistent with the current behavior, I think you'd have to add another condition, i.e. nx.is_empty(G) and len(G) == 1.
It's not a huge deal, especially given the exception class hierarchy (which, speaking of, I think the exception type on line 81 should be changed from NetworkXException to NetworkXError), but IMO it's always good to be explicit about where exactly exceptions are coming from and to preserve behavior as much as possible.
rossbar
left a comment
There was a problem hiding this comment.
I took the liberty of pushing up the last couple tweaks from my previous review - this LGTM, thanks @mohamedrezk122 !
In the light of #7393, I have adopted the same approach to solve empty graph corner case in
non_randomnessas it was also producingZeroDivisionError