From e2f76b9be8adf63f219c9c1c93618375ee494676 Mon Sep 17 00:00:00 2001 From: Erik Welch Date: Sat, 13 May 2023 07:27:50 -0500 Subject: [PATCH] Handle weights as `distance=` in testing dispatch (#6671) * Handle weights as `distance=` in testing dispatch * fix `test_intersection` This change was suggested here: https://github.com/python-graphblas/graphblas-algorithms/pull/62#issuecomment-1531810715 --- networkx/algorithms/operators/tests/test_binary.py | 3 ++- networkx/classes/backends.py | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/networkx/algorithms/operators/tests/test_binary.py b/networkx/algorithms/operators/tests/test_binary.py index d358265e37f8..59423c884fc6 100644 --- a/networkx/algorithms/operators/tests/test_binary.py +++ b/networkx/algorithms/operators/tests/test_binary.py @@ -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): diff --git a/networkx/classes/backends.py b/networkx/classes/backends.py index 06af42319760..135fa76c7044 100644 --- a/networkx/classes/backends.py +++ b/networkx/classes/backends.py @@ -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