8
8
from causal_testing .specification .causal_specification import CausalSpecification
9
9
from causal_testing .testing .base_test_case import BaseTestCase
10
10
from causal_testing .testing .estimators import CubicSplineRegressionEstimator
11
-
11
+ import pandas as pd
12
12
13
13
@dataclass
14
14
class SimulationResult :
@@ -18,6 +18,11 @@ class SimulationResult:
18
18
fault : bool
19
19
relationship : str
20
20
21
+ def to_dataframe (self ) -> pd .DataFrame :
22
+ """Convert the simulation result data to a pandas DataFrame"""
23
+ data_as_lists = {k : v if isinstance (v , list ) else [v ] for k ,v in self .data .items ()}
24
+ return pd .DataFrame (data_as_lists )
25
+
21
26
22
27
class SearchAlgorithm (ABC ): # pylint: disable=too-few-public-methods
23
28
"""Class to be inherited with the search algorithm consisting of a search function and the fitness function of the
@@ -87,14 +92,14 @@ def execute(
87
92
88
93
self .simulator .startup ()
89
94
test_result = self .simulator .run_with_config (candidate_test_case )
95
+ test_result_df = test_result .to_dataframe ()
90
96
self .simulator .shutdown ()
91
97
92
98
if custom_data_aggregator is not None :
93
99
if data_collector .data is not None :
94
100
data_collector .data = custom_data_aggregator (data_collector .data , test_result .data )
95
101
else :
96
- data_collector .data = data_collector .data .append (test_result .data , ignore_index = True )
97
-
102
+ data_collector .data = pd .concat ([data_collector .data , test_result_df ], ignore_index = True )
98
103
if test_result .fault :
99
104
print (
100
105
f"Fault found between { surrogate .treatment } causing { surrogate .outcome } . Contradiction with "
0 commit comments