@@ -100,8 +100,7 @@ def _parse_args(self) -> None:
100100 type = str ,
101101 required = False ,
102102 default = "" ,
103- help = "The name of the dataset to compute the metric on. Runs on all "
104- "datasets if not provided." ,
103+ help = "The name of the dataset to compute the metric on. Runs on all " "datasets if not provided." ,
105104 )
106105
107106 # Parse the arguments
@@ -133,9 +132,7 @@ def _load_datasets(self) -> None:
133132 dataset_names = [dataset ["name" ] for dataset in datasets_list ]
134133 if self .dataset_name :
135134 if self .dataset_name not in dataset_names :
136- raise ValueError (
137- f"Dataset { self .dataset_name } not found in the openlayer.json."
138- )
135+ raise ValueError (f"Dataset { self .dataset_name } not found in the openlayer.json." )
139136 dataset_names = [self .dataset_name ]
140137 output_directory = model ["outputDirectory" ]
141138 # Read the outputs directory for dataset folders. For each, load
@@ -152,11 +149,7 @@ def _load_datasets(self) -> None:
152149 dataset_config = json .load (f )
153150 # Merge with the dataset fields from the openlayer.json
154151 dataset_dict = next (
155- (
156- item
157- for item in datasets_list
158- if item ["name" ] == dataset_folder
159- ),
152+ (item for item in datasets_list if item ["name" ] == dataset_folder ),
160153 None ,
161154 )
162155 dataset_config = {** dataset_dict , ** dataset_config }
@@ -166,9 +159,7 @@ def _load_datasets(self) -> None:
166159 dataset_df = pd .read_csv (os .path .join (dataset_path , "dataset.csv" ))
167160 data_format = "csv"
168161 elif os .path .exists (os .path .join (dataset_path , "dataset.json" )):
169- dataset_df = pd .read_json (
170- os .path .join (dataset_path , "dataset.json" ), orient = "records"
171- )
162+ dataset_df = pd .read_json (os .path .join (dataset_path , "dataset.json" ), orient = "records" )
172163 data_format = "json"
173164 else :
174165 raise ValueError (f"No dataset found in { dataset_folder } ." )
@@ -183,14 +174,10 @@ def _load_datasets(self) -> None:
183174 )
184175 )
185176 else :
186- raise ValueError (
187- "No model found in the openlayer.json file. Cannot compute metric."
188- )
177+ raise ValueError ("No model found in the openlayer.json file. Cannot compute metric." )
189178
190179 if not datasets :
191- raise ValueError (
192- "No datasets found in the openlayer.json file. Cannot compute metric."
193- )
180+ raise ValueError ("No datasets found in the openlayer.json file. Cannot compute metric." )
194181
195182 self .datasets = datasets
196183
@@ -243,13 +230,8 @@ def compute(self, datasets: List[Dataset]) -> None:
243230 """Compute the metric on the model outputs."""
244231 for dataset in datasets :
245232 # Check if the metric has already been computed
246- if os .path .exists (
247- os .path .join (dataset .output_path , "metrics" , f"{ self .key } .json" )
248- ):
249- print (
250- f"Metric ({ self .key } ) already computed on { dataset .name } . "
251- "Skipping."
252- )
233+ if os .path .exists (os .path .join (dataset .output_path , "metrics" , f"{ self .key } .json" )):
234+ print (f"Metric ({ self .key } ) already computed on { dataset .name } . " "Skipping." )
253235 continue
254236
255237 try :
@@ -276,9 +258,7 @@ def compute_on_dataset(self, dataset: Dataset) -> MetricReturn:
276258 """Compute the metric on a specific dataset."""
277259 pass
278260
279- def _write_metric_return_to_file (
280- self , metric_return : MetricReturn , output_dir : str
281- ) -> None :
261+ def _write_metric_return_to_file (self , metric_return : MetricReturn , output_dir : str ) -> None :
282262 """Write the metric return to a file."""
283263
284264 # Create the directory if it doesn't exist
@@ -289,9 +269,7 @@ def _write_metric_return_to_file(
289269 # Convert the set to a list
290270 metric_return_dict ["added_cols" ] = list (metric_return .added_cols )
291271
292- with open (
293- os .path .join (output_dir , f"{ self .key } .json" ), "w" , encoding = "utf-8"
294- ) as f :
272+ with open (os .path .join (output_dir , f"{ self .key } .json" ), "w" , encoding = "utf-8" ) as f :
295273 json .dump (metric_return_dict , f , indent = 4 )
296274 print (f"Metric ({ self .key } ) value written to { output_dir } /{ self .key } .json" )
297275
0 commit comments