mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-24 07:35:18 +00:00
Allow passing in encoding to csv_loader (#1836)
This commit is contained in:
parent
9555bbd5bb
commit
c592b12043
@ -31,9 +31,11 @@ class CSVLoader(BaseLoader):
|
||||
file_path: str,
|
||||
source_column: Optional[str] = None,
|
||||
csv_args: Optional[Dict] = None,
|
||||
encoding: Optional[str] = None,
|
||||
):
|
||||
self.file_path = file_path
|
||||
self.source_column = source_column
|
||||
self.encoding = encoding
|
||||
if csv_args is None:
|
||||
self.csv_args = {
|
||||
"delimiter": ",",
|
||||
@ -45,7 +47,7 @@ class CSVLoader(BaseLoader):
|
||||
def load(self) -> List[Document]:
|
||||
docs = []
|
||||
|
||||
with open(self.file_path, newline="") as csvfile:
|
||||
with open(self.file_path, newline="", encoding=self.encoding) as csvfile:
|
||||
csv = DictReader(csvfile, **self.csv_args) # type: ignore
|
||||
for i, row in enumerate(csv):
|
||||
content = "\n".join(f"{k.strip()}: {v.strip()}" for k, v in row.items())
|
||||
|
Loading…
Reference in New Issue
Block a user