Bug fix in swap: directed_edge_swap and double_edge_swap #6149
Merged
dschult merged 8 commits intonetworkx:mainfrom Dec 14, 2022
Merged
Bug fix in swap: directed_edge_swap and double_edge_swap #6149dschult merged 8 commits intonetworkx:mainfrom
dschult merged 8 commits intonetworkx:mainfrom
Conversation
rossbar
approved these changes
Nov 10, 2022
Contributor
rossbar
left a comment
There was a problem hiding this comment.
LGTM - I reviewed the directed_edge_swap and double_edge_swap functions and I agree with your assessment that they are expected to fail if there are fewer than 3 or 2 edges, respectively. The explicit checking and nicer exception messages are a nice improvement!
All the suggestions are on the very nit-picky end of the spectrum, so no blockers. Thanks @paulitapb
Comment on lines
+131
to
+135
| pytest.raises(nx.NetworkXError, nx.directed_edge_swap, G) | ||
| G = nx.Graph() | ||
| G.add_nodes_from([0, 1, 2, 3]) | ||
| pytest.raises(nx.NetworkXError, nx.double_edge_swap, G) | ||
|
|
Contributor
There was a problem hiding this comment.
Just another minor suggestion: using pytest.raises as a context manager with the match= check is a really nice feature that allows us to better test we're hitting the exact exception branch that we expect.
Member
|
@paulitapb just a ping to review the comments :) |
Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
MridulS
pushed a commit
to MridulS/networkx
that referenced
this pull request
Feb 4, 2023
* raise exception if graph has no edges and test for that * Simplify code: raise exception if G has less than 3 edges * add correction * Solved bug in double_edge_swap and added tests for that. Also updated the doc entry * Update networkx/algorithms/swap.py * Added some final suggestions * add merge suggestions Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
cvanelteren
pushed a commit
to cvanelteren/networkx
that referenced
this pull request
Apr 22, 2024
* raise exception if graph has no edges and test for that * Simplify code: raise exception if G has less than 3 edges * add correction * Solved bug in double_edge_swap and added tests for that. Also updated the doc entry * Update networkx/algorithms/swap.py * Added some final suggestions * add merge suggestions Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #6144
Changed directed_edge_swap, now an exception is raised if the number of edges is less than 3. Also updated the documentation.
Changed
double_edge_swap, now an exception is raised when the function is called with a graph with fewer than 2 edges. Added some tests and updated the documentation to include a raises section that was missing.