Skip to content

Commit d931392

Browse files
convert prints to logger
1 parent 4a6958b commit d931392

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

causal_testing/json_front/json_class.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import logging
12
from pathlib import Path
23

34
from abc import ABC
@@ -16,6 +17,8 @@
1617
from causal_testing.testing.causal_test_case import CausalTestCase
1718
from causal_testing.testing.estimators import Estimator
1819

20+
logger = logging.getLogger(__name__)
21+
1922

2023
class JsonUtility(ABC):
2124
"""
@@ -113,16 +116,16 @@ def execute_tests(self, effects: dict, mutates: dict, estimators: dict, f_flag:
113116
)
114117

115118
concrete_tests, dummy = abstract_test.generate_concrete_tests(5, 0.05)
116-
print(abstract_test)
117-
print([(v.name, v.distribution) for v in abstract_test.treatment_variables])
118-
print(len(concrete_tests))
119+
logger.info(abstract_test)
120+
logger.info([(v.name, v.distribution) for v in abstract_test.treatment_variables])
121+
logger.info(len(concrete_tests))
119122
for concrete_test in concrete_tests:
120123
executed_tests += 1
121124
failed = self._execute_test_case(concrete_test, estimators[test['estimator']], f_flag)
122125
if failed:
123126
failures += 1
124127

125-
print(f"{failures}/{executed_tests} failed")
128+
logger.info(f"{failures}/{executed_tests} failed")
126129

127130
def _json_parse(self):
128131
"""Parse a JSON input file into inputs, outputs, metas and a test plan
@@ -147,7 +150,7 @@ def _populate_metas(self):
147150
f.fit()
148151
(dist, params) = list(f.get_best(method="sumsquare_error").items())[0]
149152
var.distribution = getattr(scipy.stats, dist)(**params)
150-
print(var.name, f"{dist}({params})")
153+
logger.info(var.name + f"{dist}({params})")
151154

152155
def _execute_test_case(self, causal_test_case: CausalTestCase, estimator: Estimator, f_flag: bool) -> bool:
153156
""" Executes a singular test case, prints the results and returns the test case result
@@ -174,7 +177,8 @@ def _execute_test_case(self, causal_test_case: CausalTestCase, estimator: Estima
174177
f"got {result_string}"
175178
if not test_passes:
176179
failed = True
177-
print(f" FAILED - expected {causal_test_case.expected_causal_effect}, got {causal_test_result.ate}")
180+
logger.warning(
181+
f" FAILED - expected {causal_test_case.expected_causal_effect}, got {causal_test_result.ate}")
178182
return failed
179183

180184
def _setup_test(self, causal_test_case: CausalTestCase, estimator: Estimator) -> tuple[CausalTestEngine, Estimator]:

0 commit comments

Comments
 (0)