Skip to content

Commit

Permalink
nx-cugraph: fix from_pandas_edgekey given edgekey but not edgeattr (#…
Browse files Browse the repository at this point in the history
…4550)

This fixes this: networkx/networkx#7466

We would catch this (and other changes) if we tested networkx nightlies. Someday!

I kept the buggy behavior for older versions of networkx in order to match networkx, which feels kinda silly, but also okay-ish.

Authors:
  - Erik Welch (https://github.com/eriknw)
  - Rick Ratzel (https://github.com/rlratzel)
  - Ralph Liu (https://github.com/nv-rliu)

Approvers:
  - Rick Ratzel (https://github.com/rlratzel)

URL: #4550
  • Loading branch information
eriknw authored Jul 30, 2024
1 parent f9c587a commit f20ccdd
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions python/nx-cugraph/nx_cugraph/convert_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,28 @@ def from_pandas_edgelist(
}
kwargs["edge_values"] = edge_values

if graph_class.is_multigraph() and edge_key is not None:
try:
edge_keys = df[edge_key].to_list()
except (KeyError, TypeError) as exc:
raise nx.NetworkXError(
f"Invalid edge_key argument: {edge_key}"
) from exc
if not graph_class.is_directed():
# Symmetrize the edges
edge_keys = cp.hstack(
(edge_keys, edge_keys[mask] if mask is not None else edge_keys)
)
kwargs["edge_keys"] = edge_keys
if (
graph_class.is_multigraph()
and edge_key is not None
and (
# In nx <= 3.3, `edge_key` was ignored if `edge_attr` is None
edge_attr is not None
or nx.__version__[:3] > "3.3"
)
):
try:
edge_keys = df[edge_key].to_list()
except (KeyError, TypeError) as exc:
raise nx.NetworkXError(f"Invalid edge_key argument: {edge_key}") from exc
if not graph_class.is_directed():
# Symmetrize the edges; remember, `edge_keys` is a list!
if mask is None:
edge_keys *= 2
else:
edge_keys += [
key for keep, key in zip(mask.tolist(), edge_keys) if keep
]
kwargs["edge_keys"] = edge_keys

G = graph_class.from_coo(N, src_indices, dst_indices, **kwargs)
if inplace:
Expand Down

0 comments on commit f20ccdd

Please sign in to comment.