Skip to content

Commit

Permalink
Handle weights as distance= in testing dispatch (networkx#6671)
Browse files Browse the repository at this point in the history
* Handle weights as `distance=` in testing dispatch

* fix `test_intersection`

This change was suggested here:
python-graphblas/graphblas-algorithms#62 (comment)
  • Loading branch information
eriknw authored and dschult committed Oct 23, 2023
1 parent 2b28146 commit e2f76b9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 2 additions & 1 deletion networkx/algorithms/operators/tests/test_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def test_intersection():
I2 = nx.intersection(G2, H2)
assert set(I2.nodes()) == {1, 2, 3, 4}
assert sorted(I2.edges()) == [(2, 3)]
if os.environ.get("NETWORKX_GRAPH_CONVERT", None) != "nx-loopback":
# Only test if not performing auto convert testing of backend implementations
if os.environ.get("NETWORKX_GRAPH_CONVERT", None) is None:
with pytest.raises(TypeError):
nx.intersection(G2, H)
with pytest.raises(TypeError):
Expand Down
3 changes: 3 additions & 0 deletions networkx/classes/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ def wrapper(*args, **kwds):
weight = bound.arguments["data"]
elif bound.arguments["data"]:
weight = "weight"
elif "distance" in bound.arguments:
# For ego_graph
weight = bound.arguments["distance"]
for gname in graph_list:
bound.arguments[gname] = backend.convert_from_nx(
bound.arguments[gname], weight=weight, name=name
Expand Down

0 comments on commit e2f76b9

Please sign in to comment.