Skip to content

Bug fix: UndirectedGraph does not flag up is_weighted when the edge list contains the weight.#54

Open
skojaku wants to merge 1 commit into
nicoloval:masterfrom
skojaku:develop
Open

Bug fix: UndirectedGraph does not flag up is_weighted when the edge list contains the weight.#54
skojaku wants to merge 1 commit into
nicoloval:masterfrom
skojaku:develop

Conversation

@skojaku

@skojaku skojaku commented Mar 1, 2025

Copy link
Copy Markdown

This PR is to fix a bug of UndirectedGraph object. Namely, when giving an edge list with weights, the flag is_weighted remains "False". The following code can reproduce the error.

import numpy as np
import networkx as nx
from NEMtropy import UndirectedGraph
from scipy import sparse

G = nx.karate_club_graph()
A = nx.adjacency_matrix(G)
labels = np.unique([d[1]['club'] for d in G.nodes(data=True)], return_inverse=True)[1]

src, trg, weights = sparse.find(A)
edgelist = np.vstack([src, trg, weights]).T

graph = UndirectedGraph(edgelist = edgelist)
graph.is_weighted # False

To fix this, I added one line to flag up the weight. See the diff of my edit.

@nicoloval nicoloval self-assigned this Oct 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants