Skip to content

Commit

Permalink
fix(data_preparation): update arff management
Browse files Browse the repository at this point in the history
  • Loading branch information
simonprovost committed Jul 11, 2024
1 parent b94b7a9 commit 9ecd889
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
15 changes: 9 additions & 6 deletions scikit_longitudinal/data_preparation/elsa_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,15 @@ def save_datasets(self, dir_output: str = "tmp", file_format: str = "csv"):
dataset.to_csv(f"{dir_output}/{class_name}_dataset.csv", index=False)
elif file_format.lower() == "arff":
dataset.fillna("?", inplace=True)
arff.dump(
f"{dir_output}/{class_name}_dataset.arff",
dataset.values,
relation=class_name,
names=dataset.columns,
)
arff_data = {
'description': '',
'relation': class_name,
'attributes': [(col, 'REAL' if dataset[col].dtype in ['float64', 'int64'] else 'STRING') for col in
dataset.columns],
'data': dataset.values.tolist()
}
with open(f"{dir_output}/{class_name}_dataset.arff", 'w') as f:
arff.dump(arff_data, f)
else:
raise ValueError(f"Unsupported file format: {file_format}")

Expand Down
13 changes: 7 additions & 6 deletions scikit_longitudinal/data_preparation/longitudinal_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,12 +485,13 @@ def convert(self, output_path: Union[str, Path]) -> None: # pragma: no cover

if file_ext == ".arff":
arff_data = self._csv_to_arff(self._data, self.file_path.stem)
arff.dump(
output_path,
arff_data["data"],
relation=arff_data["relation"],
names=arff_data["attributes"],
)
with open(output_path, 'w') as f:
arff.dump({
'description': '',
'relation': arff_data['relation'],
'attributes': arff_data['attributes'],
'data': arff_data['data']
}, f)
elif file_ext == ".csv":
self._data.to_csv(output_path, index=False, na_rep="")
else:
Expand Down

0 comments on commit 9ecd889

Please sign in to comment.