Skip to content

Commit 81bfafe

Browse files
update based on review comments
1 parent d387347 commit 81bfafe

2 files changed

Lines changed: 11 additions & 16 deletions

File tree

lrmodule/copy_csv.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
from pathlib import Path
33

44
import pandas as pd
5-
from lir.aggregation import Aggregation, ContextAwareDict, config_parser, pop_field
5+
from lir.aggregation import Aggregation, ContextAwareDict, config_parser, partial, pop_field
6+
from lir.util import check_type
67

78

89
class CopyCSV(Aggregation):
@@ -11,20 +12,20 @@ class CopyCSV(Aggregation):
1112
Attributes
1213
----------
1314
source_file (str): The path to the source CSV file that should be copied.
14-
target_path (str): The directory where the new CSV file will be saved. Given by the config_parser, meaning
15+
target_dir (str): The directory where the new CSV file will be saved. Given by the config_parser, meaning
1516
it is not set by the user in the configuration.
1617
columns (list[str]): A list of column names to copy from the source CSV. If empty, all columns will be copied.
1718
new_file_name (str): The name of the new CSV file. If empty, the original file name will be used.
1819
"""
1920

20-
def __init__(self, source_file: str, target_path: str, columns: list[str], new_file_name: str):
21+
def __init__(self, source_file: str, target_dir: str, columns: list[str], new_file_name: str | None):
2122
self.source_file = Path(source_file)
22-
self.target_path = Path(target_path)
23+
self.target_dir = Path(target_dir)
2324
self.columns = columns
24-
if new_file_name == "":
25-
self.new_file_name = self.target_path / self.source_file.name
25+
if new_file_name is None:
26+
self.new_file_name = self.target_dir / self.source_file.name
2627
else:
27-
self.new_file_name = self.target_path / new_file_name
28+
self.new_file_name = self.target_dir / new_file_name
2829

2930
def report(self, data) -> None:
3031
"""Do nothing. Required by parent class."""
@@ -47,6 +48,6 @@ def close(self):
4748
def copy_csv(config: ContextAwareDict, output_dir: str) -> CopyCSV:
4849
"""Parse the configuration for the CopyCSV aggregation and return an instance of it."""
4950
source_file = pop_field(config, "file")
50-
columns = pop_field(config, "columns", default=[])
51-
new_file_name = pop_field(config, "new_file_name", default="")
51+
columns = pop_field(config, "columns", default=[], validate=partial(check_type, list))
52+
new_file_name = pop_field(config, "new_file_name", required=False)
5253
return CopyCSV(source_file, output_dir, columns=columns, new_file_name=new_file_name)

validation.yaml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,7 @@ experiments:
188188
- llr_interval
189189
- method: lrmodule.copy_csv.copy_csv
190190
file: ${data_root}/breech_face_impression.csv
191-
- method: lrmodule.copy_csv.copy_csv
192-
file: ${data_root}/breech_face_impression.csv
193-
columns:
194-
- hypothesis
195-
- cmc
196-
- n
197-
new_file_name: reference_scores.csv
191+
new_file_name: source_data.csv
198192
- save_model
199193

200194

0 commit comments

Comments
 (0)