ParquetDataset¶
ParquetDataset loads and saves Hugging Face datasets in Parquet format using the datasets library.
kedro_datasets.huggingface.ParquetDataset ¶
ParquetDataset(
*,
path,
version=None,
data_files=None,
load_args=None,
save_args=None,
credentials=None,
fs_args=None,
metadata=None
)
Bases: FilesystemDataset
ParquetDataset loads/saves Hugging Face Dataset and
DatasetDict objects to/from
Parquet <https://parquet.apache.org/>_ files.
Saving IterableDataset or IterableDatasetDict objects is not
supported and will raise a DatasetError. Materialize the iterable
dataset into a Dataset or DatasetDict before saving.
Note that datasets loads a single file as a datasets.DatasetDict
with a single key called "train". You can get around this by specifying
split in the load_args. See examples for more info.
Examples:
Using the
YAML API
to load a single file. Will be loaded as a datasets.DatasetDict with a single key
"train":
reviews:
type: huggingface.ParquetDataset
path: data/01_raw/reviews.parquet
Using the
Python API
to load a datasets.DatasetDict from a single file:
>>> from datasets import Dataset
>>> from kedro_datasets.huggingface.parquet_dataset import (
... ParquetDataset,
... )
>>>
>>> data = Dataset.from_dict({"col1": [1, 2, 3], "col2": ["a", "b", "c"]})
>>> dataset = ParquetDataset(path=tmp_path / "data.parquet")
>>> dataset.save(data)
>>> loaded = dataset.load()
>>> assert "train" in loaded
Using the
YAML API
to load a datasets.Dataset from a single file:
reviews:
type: huggingface.ParquetDataset
path: data/01_raw/reviews.parquet
load_args:
split: train
Using the
Python API
to load a datasets.Dataset from a single file:
>>> from datasets import Dataset
>>> from kedro_datasets.huggingface.parquet_dataset import (
... ParquetDataset,
... )
>>>
>>> data = Dataset.from_dict({"col1": [1, 2, 3], "col2": ["a", "b", "c"]})
>>> dataset = ParquetDataset(
... path=tmp_path / "data.parquet",
... load_args={"split": "train"},
... )
>>> dataset.save(data)
>>> loaded = dataset.load()
>>> assert type(loaded.shape) is tuple # No "train" key.
Using the
YAML API
to load a datasets.DatasetDict from a directory of files:
reviews:
type: huggingface.ParquetDataset
path: data/01_raw/reviews
data_files:
labels: labels.parquet
data: data.parquet
Using the
Python API
to load a datasets.DatasetDict from a directory of files:
>>> from datasets import Dataset, DatasetDict
>>> from kedro_datasets.huggingface.parquet_dataset import (
... ParquetDataset,
... )
>>>
>>> dataset_dict = DatasetDict({
... "labels": Dataset.from_dict({"col1": [1, 2], "col2": ["a", "b"]}),
... "data": Dataset.from_dict({"col1": [3, 4], "col2": ["c", "d"]}),
... })
>>> dataset = ParquetDataset(
... path=tmp_path,
... data_files={
... "labels": "labels.parquet",
... "data": "data.parquet",
... },
... )
>>> dataset.save(dataset_dict)
>>> loaded = dataset.load()
Parameters:
-
path(str | PathLike) –Path to a file or directory for persisting Hugging Face datasets. Supports local paths,
os.PathLikeobjects, and remote URIs (e.g.s3://bucket/data). -
version(Version | None, default:None) –If specified, should be an instance of
kedro.io.core.Version. If itsloadattribute is None, the latest version will be loaded. If itssaveattribute is None, save version will be autogenerated. -
data_files(dict[str, str] | None, default:None) –Mapping of split name to filename for loading and saving a
DatasetDictfrom a directory (e.g.{"train": "train.csv"}). The keys must match the split names of theDatasetDictbeing saved, and the filenames must use the correct extension for the format (e.g..csvforCSVDataset). -
load_args(dict[str, Any] | None, default:None) –Additional keyword arguments passed to the underlying load function. This cannot include
data_files; use the top-leveldata_filesargument instead. -
save_args(dict[str, Any] | None, default:None) –Additional keyword arguments passed to the underlying save function. This cannot include
data_files; use the top-leveldata_filesargument instead. -
credentials(dict[str, Any] | None, default:None) –Credentials for the underlying filesystem (e.g.
key/secretfor S3). Passed to thestorage_optionsparameter in the underlyingdatasetsimplementation. -
fs_args(dict[str, Any] | None, default:None) –Extra arguments passed to the
fsspecfilesystem initialiser. Passed to thestorage_optionsparameter in the underlyingdatasetsimplementation. -
metadata(dict[str, Any] | None, default:None) –Any arbitrary metadata. This is ignored by Kedro but may be consumed by users or external plugins.
Source code in kedro_datasets/huggingface/_base.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
load ¶
load()
Source code in kedro_datasets/huggingface/_base.py
116 117 118 | |
save ¶
save(data)
Source code in kedro_datasets/huggingface/_base.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | |