|
10 | 10 | from itertools import permutations |
11 | 11 |
|
12 | 12 | import networkx as nx |
| 13 | +import numpy as np |
13 | 14 | import pandas as pd |
14 | 15 | import rustworkx as rx |
15 | 16 |
|
@@ -207,28 +208,27 @@ def evaluate_tests(self, causal_dag: CausalDAG) -> pd.DataFrame: |
207 | 208 |
|
208 | 209 | results = [] |
209 | 210 |
|
210 | | - # We use "silent=False" here to allow for inestimable edges, but it'd be good to have a more stringent |
211 | | - # error catching strategy to catch "genuine" problems (e.g. to do with the structure of the data) |
212 | | - for test_case, result in zip(ctf.test_cases, ctf.run_tests(silent=False)): |
213 | | - if result.effect_estimate is None: |
| 211 | + for test_case, result in zip(ctf.test_cases, ctf.test_cases): |
| 212 | + try: |
| 213 | + result = test_case.execute_test() |
214 | 214 | results.append( |
215 | 215 | { |
216 | | - "result": TestResult.INESTIMABLE, |
| 216 | + "result": ( |
| 217 | + TestResult.PASS if test_case.expected_causal_effect.apply(result) else TestResult.FAIL |
| 218 | + ), |
217 | 219 | "expected_effect": test_case.expected_causal_effect.__class__.__name__, |
218 | 220 | "treatment": test_case.base_test_case.treatment_variable.name, |
219 | 221 | "outcome": test_case.base_test_case.outcome_variable.name, |
| 222 | + "effect": effect_direction(result), |
220 | 223 | } |
221 | 224 | ) |
222 | | - else: |
| 225 | + except np.linalg.LinAlgError: |
223 | 226 | results.append( |
224 | 227 | { |
225 | | - "result": ( |
226 | | - TestResult.PASS if test_case.expected_causal_effect.apply(result) else TestResult.FAIL |
227 | | - ), |
| 228 | + "result": TestResult.INESTIMABLE, |
228 | 229 | "expected_effect": test_case.expected_causal_effect.__class__.__name__, |
229 | 230 | "treatment": test_case.base_test_case.treatment_variable.name, |
230 | 231 | "outcome": test_case.base_test_case.outcome_variable.name, |
231 | | - "effect": effect_direction(result), |
232 | 232 | } |
233 | 233 | ) |
234 | 234 |
|
|
0 commit comments