Skip to content

Commit

Permalink
FIX: Match the doc description while copying over data (networkx#7092)
Browse files Browse the repository at this point in the history
* FIX: Match the doc description while copying over data

* check for graph data too
  • Loading branch information
MridulS authored and cvanelteren committed Apr 22, 2024
1 parent b3dfa6f commit f7e8d57
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions networkx/algorithms/operators/binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def difference(G, H):
# create new graph
if not G.is_multigraph() == H.is_multigraph():
raise nx.NetworkXError("G and H must both be graphs or multigraphs.")
R = nx.create_empty_copy(G)
R = nx.create_empty_copy(G, with_data=False)

if set(G) != set(H):
raise nx.NetworkXError("Node sets of graphs not equal")
Expand Down Expand Up @@ -258,7 +258,7 @@ def symmetric_difference(G, H):
# create new graph
if not G.is_multigraph() == H.is_multigraph():
raise nx.NetworkXError("G and H must both be graphs or multigraphs.")
R = nx.create_empty_copy(G)
R = nx.create_empty_copy(G, with_data=False)

if set(G) != set(H):
raise nx.NetworkXError("Node sets of graphs not equal")
Expand Down
3 changes: 3 additions & 0 deletions networkx/algorithms/operators/tests/test_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ def test_difference_attributes():
assert set(gh.nodes()) == set(g.nodes())
assert set(gh.nodes()) == set(h.nodes())
assert sorted(gh.edges()) == []
# node and graph data should not be copied over
assert gh.nodes.data() != g.nodes.data()
assert gh.graph != g.graph


def test_difference_multigraph_attributes():
Expand Down

0 comments on commit f7e8d57

Please sign in to comment.