Skip to content

Commit 125c6a6

Browse files
black + pylint
1 parent 1d1ea3b commit 125c6a6

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

causal_testing/json_front/json_class.py

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import logging
77

88
from dataclasses import dataclass
9-
from enum import Enum
109
from pathlib import Path
1110

1211
import pandas as pd
@@ -106,12 +105,14 @@ def generate_tests(self, effects: dict, mutates: dict, estimators: dict, f_flag:
106105

107106
concrete_tests, dummy = abstract_test.generate_concrete_tests(5, 0.05)
108107
failures = self._execute_tests(concrete_tests, estimators, test, f_flag)
109-
msg = f"Executing test: {test['name']} \n" + \
110-
f"abstract_test \n" + \
111-
f"{abstract_test} \n" + \
112-
f"{abstract_test.treatment_variable.name},{abstract_test.treatment_variable.distribution} \n" + \
113-
f"Number of concrete tests for test case: {str(len(concrete_tests))} \n" + \
114-
f"{failures}/{len(concrete_tests)} failed for {test['name']}"
108+
msg = (
109+
f"Executing test: {test['name']} \n"
110+
+ "abstract_test \n"
111+
+ f"{abstract_test} \n"
112+
+ f"{abstract_test.treatment_variable.name},{abstract_test.treatment_variable.distribution} \n"
113+
+ f"Number of concrete tests for test case: {str(len(concrete_tests))} \n"
114+
+ f"{failures}/{len(concrete_tests)} failed for {test['name']}"
115+
)
115116
self._append_to_file(msg, logging.INFO)
116117

117118
def _execute_tests(self, concrete_tests, estimators, test, f_flag):
@@ -177,8 +178,9 @@ def _execute_test_case(self, causal_test_case: CausalTestCase, estimator: Estima
177178
)
178179
if not test_passes:
179180
failed = True
180-
self._append_to_file(f"FAILED- expected {causal_test_case.expected_causal_effect}, got {result_string}",
181-
logging.WARNING)
181+
self._append_to_file(
182+
f"FAILED- expected {causal_test_case.expected_causal_effect}, got {result_string}", logging.WARNING
183+
)
182184
return failed
183185

184186
def _setup_test(self, causal_test_case: CausalTestCase, estimator: Estimator) -> tuple[CausalTestEngine, Estimator]:
@@ -217,13 +219,24 @@ def add_modelling_assumptions(self, estimation_model: Estimator): # pylint: dis
217219
return
218220

219221
def _append_to_file(self, line: str, log_level: int = None):
220-
with open(self.output_path, "a") as f:
221-
f.write(line + "\n")
222+
""" Appends given line(s) to the current output file. If log_level is specified it also logs that message to the
223+
logging level.
224+
:param line: The line or lines of text to be appended to the file
225+
:param log_level: An integer representing the logging level as specified by pythons inbuilt logging module. It
226+
is possible to use the inbuilt logging level variables such as logging.INFO and logging.WARNING
227+
"""
228+
with open(self.output_path, "a", encoding='utf-8') as f:
229+
f.write(line + "\n", )
222230
if log_level:
223231
logger.log(level=log_level, msg=line)
224232

225233
@staticmethod
226234
def check_file_exists(output_path: Path, overwrite: bool):
235+
""" Method that checks if the given path to an output file already exists. If overwrite is true the check is
236+
passed.
237+
:param output_path: File path for the output file of the JSON Frontend
238+
:param overwrite: bool that if true, the current file can be overwritten
239+
"""
227240
if not overwrite and output_path.is_file():
228241
raise FileExistsError(f"Chosen file output ({output_path}) already exists")
229242

@@ -243,8 +256,9 @@ def get_args(test_args=None) -> argparse.Namespace:
243256
)
244257
parser.add_argument(
245258
"-w",
246-
help="Specify to overwrite any existing output files. This can lead to the loss of existing outputs if not careful",
247-
action="store_true"
259+
help="Specify to overwrite any existing output files. This can lead to the loss of existing outputs if not "
260+
"careful",
261+
action="store_true",
248262
)
249263
parser.add_argument(
250264
"--log_path",

causal_testing/testing/estimators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def _run_logistic_regression(self, data) -> RegressionResultsWrapper:
158158
model = smf.logit(formula=self.formula, data=data).fit(disp=0)
159159
return model
160160

161-
def estimate(self, data: pd.DataFrame, adjustment_config:dict = None) -> RegressionResultsWrapper:
161+
def estimate(self, data: pd.DataFrame, adjustment_config: dict = None) -> RegressionResultsWrapper:
162162
"""add terms to the dataframe and estimate the outcome from the data
163163
:param data: A pandas dataframe containing execution data from the system-under-test.
164164
:param adjustment_config: Dictionary containing the adjustment configuration of the adjustment set

0 commit comments

Comments
 (0)