Haystack custom components for your favourite dataframe library.
Project description
Dataframes Haystack
📃 Description
dataframes-haystack
is an extension for Haystack 2 that enables integration with dataframe libraries.
The dataframe libraries currently supported are:
The library offers various custom Converters components to transform dataframes into Haystack Document
objects:
DataFrameFileToDocument
is a main generic converter that reads files using a dataframe backend and converts them intoDocument
objects.FileToPandasDataFrame
andFileToPolarsDataFrame
read files and convert them into dataframes.PandasDataFrameConverter
orPolarsDataFrameConverter
convert data stored in dataframes into HaystackDocument
objects.
dataframes-haystack
supports reading files in various formats:
- csv, json, parquet, excel, html, xml, orc, pickle, fixed-width format for
pandas
. See the pandas documentation for more details. - csv, json, parquet, excel, avro, delta, ipc for
polars
. See the polars documentation for more details.
🛠️ Installation
# for pandas (pandas is already included in `haystack-ai`)
pip install dataframes-haystack
# for polars
pip install "dataframes-haystack[polars]"
💻 Usage
[!TIP] See the Example Notebooks for complete examples.
DataFrameFileToDocument
You can leverage both pandas
and polars
backends (thanks to narwhals
) to read your data!
from dataframes_haystack.components.converters import DataFrameFileToDocument
converter = DataFrameFileToDocument(content_column="text_str")
documents = converter.run(files=["file1.csv", "file2.csv"])
>>> documents
{'documents': [
Document(id=0, content: 'Hello world', meta: {}),
Document(id=1, content: 'Hello everyone', meta: {})
]}
Pandas
FileToPandasDataFrame
from dataframes_haystack.components.converters.pandas import FileToPandasDataFrame
converter = FileToPandasDataFrame(file_format="csv")
output_dataframe = converter.run(
file_paths=["data/doc1.csv", "data/doc2.csv"]
)
Result:
>>> output_dataframe
{'dataframe': <pandas.DataFrame>}
PandasDataFrameConverter
import pandas as pd
from dataframes_haystack.components.converters.pandas import PandasDataFrameConverter
df = pd.DataFrame({
"text": ["Hello world", "Hello everyone"],
"filename": ["doc1.txt", "doc2.txt"],
})
converter = PandasDataFrameConverter(content_column="text", meta_columns=["filename"])
documents = converter.run(df)
Result:
>>> documents
{'documents': [
Document(id=0, content: 'Hello world', meta: {'filename': 'doc1.txt'}),
Document(id=1, content: 'Hello everyone', meta: {'filename': 'doc2.txt'})
]}
Polars
FileToPolarsDataFrame
from dataframes_haystack.components.converters.polars import FileToPolarsDataFrame
converter = FileToPolarsDataFrame(file_format="csv")
output_dataframe = converter.run(
file_paths=["data/doc1.csv", "data/doc2.csv"]
)
Result:
>>> output_dataframe
{'dataframe': <polars.DataFrame>}
PolarsDataFrameConverter
import polars as pl
from dataframes_haystack.components.converters.polars import PolarsDataFrameConverter
df = pl.DataFrame({
"text": ["Hello world", "Hello everyone"],
"filename": ["doc1.txt", "doc2.txt"],
})
converter = PolarsDataFrameConverter(content_column="text", meta_columns=["filename"])
documents = converter.run(df)
Result:
>>> documents
{'documents': [
Document(id=0, content: 'Hello world', meta: {'filename': 'doc1.txt'}),
Document(id=1, content: 'Hello everyone', meta: {'filename': 'doc2.txt'})
]}
🤝 Contributing
Do you have an idea for a new feature? Did you find a bug that needs fixing?
Feel free to open an issue or submit a PR!
Setup development environment
Requirements: hatch
, pre-commit
- Clone the repository
- Run
hatch shell
to create and activate a virtual environment - Run
pre-commit install
to install the pre-commit hooks. This will force the linting and formatting checks.
Run tests
- Linting and formatting checks:
hatch run lint:fmt
- Unit tests:
hatch run test-cov-all
✍️ License
dataframes-haystack
is distributed under the terms of the MIT license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file dataframes_haystack-0.0.4.tar.gz
.
File metadata
- Download URL: dataframes_haystack-0.0.4.tar.gz
- Upload date:
- Size: 163.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7a4b95507eb0836a7279d8c11002092ee8efbb247d6de1ba17d172052fb38f3 |
|
MD5 | beb8ee592edd1a533c21def9a89dc101 |
|
BLAKE2b-256 | eb03546fd5f508554c1529eac8ea9ca73a06431ea919a07859e31f1d6ce28de3 |
File details
Details for the file dataframes_haystack-0.0.4-py3-none-any.whl
.
File metadata
- Download URL: dataframes_haystack-0.0.4-py3-none-any.whl
- Upload date:
- Size: 12.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1b29cc09e9a165608ab4d98e33dd595f71c51799df5394eddffc412f309beba |
|
MD5 | b263080ed239a69e938cece0a9dbced5 |
|
BLAKE2b-256 | 9dd668ebf746f93fa9e99e3ba30879a612d3319e4e806cc41075ffd21d09ef8f |