Skip to content

Commit 630add7

Browse files
committed
update input to add_edges_from
- Modified input to add_edges_from to only take the edges which connects the existing nodes, to avoid internal creation of obsolete nodes
1 parent b62c931 commit 630add7

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

chebai/preprocessing/datasets/chebi.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,16 @@ def _extract_class_hierarchy(self, data_path: str) -> nx.DiGraph:
258258
g = nx.DiGraph()
259259
for n in elements:
260260
g.add_node(n["id"], **n)
261-
g.add_edges_from([(p, q["id"]) for q in elements for p in q["parents"]])
261+
262+
# Only take the edges which connects the existing nodes, to avoid internal creation of obsolete nodes
263+
g.add_edges_from(
264+
[
265+
(p, q["id"])
266+
for q in elements
267+
for p in q["parents"]
268+
if g.has_node(p) and g.has_node(q["id"])
269+
]
270+
)
262271

263272
print("Compute transitive closure")
264273
return nx.transitive_closure_dag(g)

0 commit comments

Comments
 (0)