Skip to content

Commit 70d089f

Browse files
authored
Merge branch 'main' into surrogate-fix
2 parents 4b4663a + 5230bfc commit 70d089f

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

causal_testing/specification/causal_dag.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,12 @@ class CausalDAG(nx.DiGraph):
133133
def __init__(self, dot_path: str = None, **attr):
134134
super().__init__(**attr)
135135
if dot_path:
136-
pydot_graph = pydot.graph_from_dot_file(dot_path)
136+
with open(dot_path, 'r', encoding='utf-8') as file:
137+
dot_content = file.read().replace('\n', '')
138+
# Previously, we used pydot_graph_from_file() to read in the dot_path directly, however,
139+
# this method does not currently have a way of removing spurious nodes.
140+
# Workaround: Read in the file using open(), remove new lines, and then create the pydot_graph.
141+
pydot_graph = pydot.graph_from_dot_data(dot_content)
137142
self.graph = nx.DiGraph(nx.drawing.nx_pydot.from_pydot(pydot_graph[0]))
138143
else:
139144
self.graph = nx.DiGraph()

0 commit comments

Comments
 (0)