@@ -48,7 +48,6 @@ class JsonUtility:
48
48
def __init__ (self , output_path : str , output_overwrite : bool = False ):
49
49
self .input_paths = None
50
50
self .variables = {"inputs" : {}, "outputs" : {}, "metas" : {}}
51
- self .data = []
52
51
self .test_plan = None
53
52
self .scenario = None
54
53
self .causal_specification = None
@@ -69,6 +68,7 @@ def set_paths(self, json_path: str, dag_path: str, data_paths: list[str] = None)
69
68
70
69
def setup (self , scenario : Scenario ):
71
70
"""Function to populate all the necessary parts of the json_class needed to execute tests"""
71
+ data = []
72
72
self .scenario = scenario
73
73
self ._get_scenario_variables ()
74
74
self .scenario .setup_treatment_variables ()
@@ -80,22 +80,23 @@ def setup(self, scenario: Scenario):
80
80
self .test_plan = json .load (f )
81
81
# Populate the data
82
82
if self .input_paths .data_paths :
83
- self . data = pd .concat ([pd .read_csv (data_file , header = 0 ) for data_file in self .input_paths .data_paths ])
84
- if len (self . data ) == 0 :
83
+ data = pd .concat ([pd .read_csv (data_file , header = 0 ) for data_file in self .input_paths .data_paths ])
84
+ if len (data ) == 0 :
85
85
raise ValueError (
86
86
"No data found, either provide a path to a file containing data or manually populate the .data "
87
87
"attribute with a dataframe before calling .setup()"
88
88
)
89
- self ._populate_metas ()
90
89
self .data_collector = ObservationalDataCollector (
91
- self .scenario , self .data )
90
+ self .scenario , data )
91
+ self ._populate_metas ()
92
+
92
93
93
94
def _create_abstract_test_case (self , test , mutates , effects ):
94
95
assert len (test ["mutations" ]) == 1
95
96
treatment_var = next (self .scenario .variables [v ] for v in test ["mutations" ])
96
97
97
98
if not treatment_var .distribution :
98
- fitter = Fitter (self .data [treatment_var .name ], distributions = get_common_distributions ())
99
+ fitter = Fitter (self .data_collector . data [treatment_var .name ], distributions = get_common_distributions ())
99
100
fitter .fit ()
100
101
(dist , params ) = list (fitter .get_best (method = "sumsquare_error" ).items ())[0 ]
101
102
treatment_var .distribution = getattr (scipy .stats , dist )(** params )
@@ -247,10 +248,10 @@ def _populate_metas(self):
247
248
Populate data with meta-variable values and add distributions to Causal Testing Framework Variables
248
249
"""
249
250
for meta in self .scenario .variables_of_type (Meta ):
250
- meta .populate (self .data )
251
+ meta .populate (self .data_collector . data )
251
252
252
253
def _execute_test_case (
253
- self , causal_test_case : CausalTestCase , test : Iterable [ Mapping ] ,
254
+ self , causal_test_case : CausalTestCase , test : Mapping ,
254
255
f_flag : bool
255
256
) -> (bool , CausalTestResult ):
256
257
"""Executes a singular test case, prints the results and returns the test case result
@@ -309,7 +310,6 @@ def _setup_test(
309
310
"control_value" : causal_test_case .control_value ,
310
311
"adjustment_set" : minimal_adjustment_set ,
311
312
"outcome" : causal_test_case .outcome_variable .name ,
312
- "df" : self .data_collector .collect_data (),
313
313
"effect_modifiers" : causal_test_case .effect_modifier_configuration ,
314
314
"alpha" : test ["alpha" ] if "alpha" in test else 0.05 ,
315
315
}
0 commit comments