Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Commit

Permalink
Update base.py (#839)
Browse files Browse the repository at this point in the history
* Update base.py

support for configure delimiter and quotechar in paged_csv

* Linting and formatting

* Linting and formatting v2

* Remove | NoneType on load_data because failt test_library_matches

---------

Co-authored-by: miezz <miezz@yoizen.com>
  • Loading branch information
miezzi and miezz committed Feb 2, 2024
1 parent b421f36 commit 4a96830
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions llama_hub/file/paged_csv/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
A parser for tabular data files.
"""

from pathlib import Path
from typing import Any, Dict, List, Optional

Expand All @@ -26,14 +27,18 @@ def __init__(self, *args: Any, encoding: str = "utf-8", **kwargs: Any) -> None:
self._encoding = encoding

def load_data(
self, file: Path, extra_info: Optional[Dict] = None
self,
file: Path,
extra_info: Optional[Dict] = None,
delimiter: str = ",",
quotechar: str = '"',
) -> List[Document]:
"""Parse file."""
import csv

docs = []
with open(file, "r", encoding=self._encoding) as fp:
csv_reader = csv.DictReader(fp) # type: ignore
csv_reader = csv.DictReader(f=fp, delimiter=delimiter, quotechar=quotechar) # type: ignore
for row in csv_reader:
docs.append(
Document(
Expand Down

0 comments on commit 4a96830

Please sign in to comment.