Merge pull request #560 from ravindraprasad75/fix-csv-issue

fixed the the csv file reading issue
This commit is contained in:
Iván Martínez 2023-06-01 10:25:37 +02:00 committed by GitHub
commit 9d47d03d18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 5 deletions

View File

@ -81,16 +81,15 @@ LOADER_MAPPING = {
}
def load_single_document(file_path: str) -> Document:
def load_single_document(file_path: str) -> List[Document]:
ext = "." + file_path.rsplit(".", 1)[-1]
if ext in LOADER_MAPPING:
loader_class, loader_args = LOADER_MAPPING[ext]
loader = loader_class(file_path, **loader_args)
return loader.load()[0]
return loader.load()
raise ValueError(f"Unsupported file extension '{ext}'")
def load_documents(source_dir: str, ignored_files: List[str] = []) -> List[Document]:
"""
Loads all documents from the source documents directory, ignoring specified files
@ -105,8 +104,8 @@ def load_documents(source_dir: str, ignored_files: List[str] = []) -> List[Docum
with Pool(processes=os.cpu_count()) as pool:
results = []
with tqdm(total=len(filtered_files), desc='Loading new documents', ncols=80) as pbar:
for i, doc in enumerate(pool.imap_unordered(load_single_document, filtered_files)):
results.append(doc)
for i, docs in enumerate(pool.imap_unordered(load_single_document, filtered_files)):
results.extend(docs)
pbar.update()
return results