File tree Expand file tree Collapse file tree 3 files changed +9
-3
lines changed
causal_testing/specification Expand file tree Collapse file tree 3 files changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -525,7 +525,10 @@ def to_dot(self) -> str:
525
525
"""Return a string of the DOT representation of the causal DAG.
526
526
:return DOT string of the DAG.
527
527
"""
528
- return str (nx .nx_pydot .to_pydot (self .graph ))
528
+ dotstring = "digraph G {\n "
529
+ dotstring += "" .join ([f"{ a } -> { b } ;\n " for a , b in self .graph .edges ])
530
+ dotstring += "}"
531
+ return dotstring
529
532
530
533
def __str__ (self ):
531
534
return f"Nodes: { self .graph .nodes } \n Edges: { self .graph .edges } "
Original file line number Diff line number Diff line change @@ -116,7 +116,6 @@ def test_generate_coefficient_tests_from_json(self):
116
116
}
117
117
]
118
118
}
119
- print (self .json_class .causal_specification .causal_dag .to_dot ())
120
119
self .json_class .test_plan = example_test
121
120
effects = {"NoEffect" : NoEffect ()}
122
121
estimators = {"LinearRegressionEstimator" : LinearRegressionEstimator }
Original file line number Diff line number Diff line change @@ -73,7 +73,7 @@ class TestCausalDAG(unittest.TestCase):
73
73
def setUp (self ) -> None :
74
74
temp_dir_path = create_temp_dir_if_non_existent ()
75
75
self .dag_dot_path = os .path .join (temp_dir_path , "dag.dot" )
76
- dag_dot = """digraph G { A -> B; B -> C; D -> A; D -> C}"""
76
+ dag_dot = """digraph G { A -> B; B -> C; D -> A; D -> C; }"""
77
77
f = open (self .dag_dot_path , "w" )
78
78
f .write (dag_dot )
79
79
f .close ()
@@ -99,6 +99,10 @@ def test_empty_casual_dag(self):
99
99
causal_dag = CausalDAG ()
100
100
assert list (causal_dag .graph .nodes ) == [] and list (causal_dag .graph .edges ) == []
101
101
102
+ def test_to_dot (self ):
103
+ causal_dag = CausalDAG (self .dag_dot_path )
104
+ self .assertEqual (causal_dag .to_dot (), """digraph G {\n A -> B;\n B -> C;\n D -> A;\n D -> C;\n }""" )
105
+
102
106
def tearDown (self ) -> None :
103
107
remove_temp_dir_if_existent ()
104
108
You can’t perform that action at this time.
0 commit comments