mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-26 16:43:35 +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,
|
file_path: str,
|
||||||
source_column: Optional[str] = None,
|
source_column: Optional[str] = None,
|
||||||
csv_args: Optional[Dict] = None,
|
csv_args: Optional[Dict] = None,
|
||||||
|
encoding: Optional[str] = None,
|
||||||
):
|
):
|
||||||
self.file_path = file_path
|
self.file_path = file_path
|
||||||
self.source_column = source_column
|
self.source_column = source_column
|
||||||
|
self.encoding = encoding
|
||||||
if csv_args is None:
|
if csv_args is None:
|
||||||
self.csv_args = {
|
self.csv_args = {
|
||||||
"delimiter": ",",
|
"delimiter": ",",
|
||||||
@ -45,7 +47,7 @@ class CSVLoader(BaseLoader):
|
|||||||
def load(self) -> List[Document]:
|
def load(self) -> List[Document]:
|
||||||
docs = []
|
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
|
csv = DictReader(csvfile, **self.csv_args) # type: ignore
|
||||||
for i, row in enumerate(csv):
|
for i, row in enumerate(csv):
|
||||||
content = "\n".join(f"{k.strip()}: {v.strip()}" for k, v in row.items())
|
content = "\n".join(f"{k.strip()}: {v.strip()}" for k, v in row.items())
|
||||||
|
Loading…
Reference in New Issue
Block a user