Skip to content

Commit

Permalink
Move dict creation outside of for loop
Browse files Browse the repository at this point in the history
  • Loading branch information
sjrl committed Feb 10, 2025
1 parent ca20f74 commit dc12957
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions haystack/components/preprocessors/csv_document_splitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,11 @@ def run(self, documents: List[Document]) -> Dict[str, List[Document]]:
if len(documents) == 0:
return {"documents": documents}

resolved_read_csv_kwargs = {"header": None, "skip_blank_lines": False, "dtype": object, **self.read_csv_kwargs}

split_documents = []
for document in documents:
try:
resolved_read_csv_kwargs = {
"header": None,
"skip_blank_lines": False,
"dtype": object,
**self.read_csv_kwargs,
}
df = pd.read_csv(StringIO(document.content), **resolved_read_csv_kwargs) # type: ignore
except Exception as e:
logger.error(f"Error processing document {document.id}. Keeping it, but skipping splitting. Error: {e}")
Expand Down

0 comments on commit dc12957

Please sign in to comment.