Skip to content

Bug fix in swap: directed_edge_swap and double_edge_swap #6149

Merged
dschult merged 8 commits intonetworkx:mainfrom
paulitapb:bug_fix_swap_double_edge_swap
Dec 14, 2022
Merged

Bug fix in swap: directed_edge_swap and double_edge_swap #6149
dschult merged 8 commits intonetworkx:mainfrom
paulitapb:bug_fix_swap_double_edge_swap

Conversation

@paulitapb
Copy link
Copy Markdown
Member

@paulitapb paulitapb commented Oct 29, 2022

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.

@paulitapb paulitapb changed the title Bug fix in swap: double edge swap Bug fix in swap: directed_egdge_swap and double_edge_swap Oct 29, 2022
@paulitapb paulitapb changed the title Bug fix in swap: directed_egdge_swap and double_edge_swap Bug fix in swap: directed_edge_swap and double_edge_swap Oct 29, 2022
Copy link
Copy Markdown
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.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

great!

@jarrodmillman jarrodmillman added this to the networkx-3.0 milestone Nov 22, 2022
@rossbar rossbar modified the milestones: networkx-3.0, networkx-3.1 Nov 29, 2022
@MridulS
Copy link
Copy Markdown
Member

MridulS commented Dec 12, 2022

@paulitapb just a ping to review the comments :)

@dschult dschult merged commit 247231f into networkx:main Dec 14, 2022
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

directed_edge_swap: ZeroDivisionError when passing a digraph without edges

5 participants