Skip to content

Commit 1166240

Browse files
read and concat multiple csvs
1 parent 729e4e2 commit 1166240

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

causal_testing/json_front/json_class.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import argparse
55
import json
66
import logging
7+
import tempfile
78

89
from abc import ABC
910
from dataclasses import dataclass
@@ -46,20 +47,20 @@ class JsonUtility(ABC):
4647
def __init__(self, log_path):
4748
self.paths = None
4849
self.variables = None
49-
self.data = None
50+
self.data = list()
5051
self.test_plan = None
5152
self.modelling_scenario = None
5253
self.causal_specification = None
5354
self.setup_logger(log_path)
5455

55-
def set_paths(self, json_path: str, dag_path: str, data_path: str):
56+
def set_paths(self, json_path: str, dag_path: str, data_paths: str):
5657
"""
5758
Takes a path of the directory containing all scenario specific files and creates individual paths for each file
5859
:param json_path: string path representation to .json file containing test specifications
5960
:param dag_path: string path representation to the .dot file containing the Causal DAG
6061
:param data_path: string path representation to the data file
6162
"""
62-
self.paths = JsonClassPaths(json_path=json_path, dag_path=dag_path, data_path=data_path)
63+
self.paths = JsonClassPaths(json_path=json_path, dag_path=dag_path, data_paths=data_paths)
6364

6465
def set_variables(self, inputs: list[dict], outputs: list[dict], metas: list[dict]):
6566
"""Populate the Causal Variables
@@ -132,8 +133,9 @@ def _json_parse(self):
132133
"""Parse a JSON input file into inputs, outputs, metas and a test plan"""
133134
with open(self.paths.json_path, encoding="utf-8") as f:
134135
self.test_plan = json.load(f)
135-
136-
self.data = pd.read_csv(self.paths.data_path)
136+
for data_file in self.paths.data_paths:
137+
df = pd.read_csv(data_file, header=0)
138+
self.data.append(df)
137139

138140
def _populate_metas(self):
139141
"""
@@ -252,6 +254,7 @@ def get_args(test_args=None) -> argparse.Namespace:
252254
"--data_path",
253255
help="Specify path to file containing runtime data",
254256
required=True,
257+
nargs='+',
255258
)
256259
parser.add_argument(
257260
"--dag_path",
@@ -282,7 +285,7 @@ class JsonClassPaths:
282285
def __init__(self, json_path: str, dag_path: str, data_path: str):
283286
self.json_path = Path(json_path)
284287
self.dag_path = Path(dag_path)
285-
self.data_path = Path(data_path)
288+
self.data_paths = [Path(path) for path in data_path]
286289

287290

288291
@dataclass()

0 commit comments

Comments
 (0)