Skip to content

Commit db0b170

Browse files
committed
fix: optimize generate overwritten output for csvs
1 parent ef29fff commit db0b170

1 file changed

Lines changed: 8 additions & 11 deletions

File tree

preprocessing/loader.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -178,20 +178,17 @@ def overwrite_with_results(
178178

179179
output_path = Path.cwd() / export_path.name
180180

181-
preprocessed_dict = {doc.doc_id: doc for doc in preprocessed_docs}
181+
replacement_map = {
182+
doc.doc_id: " ".join(doc.tokens) for doc in preprocessed_docs
183+
}
182184

183185
updated_df = self.df.copy()
184186

185-
for idx, row in updated_df.iterrows():
186-
doc_id = self._extract_doc_id(row, self.id_column)
187-
188-
preprocessed = preprocessed_dict.get(doc_id)
189-
190-
if not preprocessed:
191-
continue
192-
193-
updated_df.at[idx, self.attribute] = " ".join(preprocessed.tokens)
187+
updated_df[self.attribute] = (
188+
updated_df[self.id_column]
189+
.map(replacement_map)
190+
.fillna(updated_df[self.attribute])
191+
)
194192

195193
updated_df.to_csv(output_path, index=False)
196-
197194
logger.info(f"CSV file successfully written to: {output_path}")

0 commit comments

Comments
 (0)