mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-06 21:43:44 +00:00
community[patch]: added content_columns option to CSVLoader (#23809)
**Description:** Adding a new option to the CSVLoader that allows us to implicitly specify the columns that are used for generating the Document content. Currently these are implicitly set as "all fields not part of the metadata_columns". In some cases however it is useful to have a field both as a metadata and as part of the document content.
This commit is contained in:
committed by
GitHub
parent
ab527027ac
commit
6a8f8a56ac
@@ -108,6 +108,27 @@ class TestCSVLoader:
|
||||
# Assert
|
||||
assert result == expected_docs
|
||||
|
||||
def test_csv_loader_content_columns(self) -> None:
|
||||
# Setup
|
||||
file_path = self._get_csv_file_path("test_none_col.csv")
|
||||
expected_docs = [
|
||||
Document(
|
||||
page_content="column1: value1\n" "column3: value3",
|
||||
metadata={"source": file_path, "row": 0},
|
||||
),
|
||||
Document(
|
||||
page_content="column1: value6\n" "column3: value8",
|
||||
metadata={"source": file_path, "row": 1},
|
||||
),
|
||||
]
|
||||
|
||||
# Exercise
|
||||
loader = CSVLoader(file_path=file_path, content_columns=("column1", "column3"))
|
||||
result = loader.load()
|
||||
|
||||
# Assert
|
||||
assert result == expected_docs
|
||||
|
||||
# utility functions
|
||||
def _get_csv_file_path(self, file_name: str) -> str:
|
||||
return str(Path(__file__).resolve().parent / "test_docs" / "csv" / file_name)
|
||||
|
Reference in New Issue
Block a user