EagerPolarsDataset¶
EagerPolarsDataset loads and saves data using Polars in eager execution mode.
kedro_datasets.polars.EagerPolarsDataset ¶
EagerPolarsDataset(
*,
filepath,
file_format,
load_args=None,
save_args=None,
version=None,
credentials=None,
fs_args=None,
metadata=None
)
Bases: AbstractVersionedDataset[DataFrame, DataFrame]
polars.EagerPolarsDataset loads/saves data from/to a data file using an underlying
filesystem (e.g.: local, S3, GCS). It uses polars to handle the dynamically select the
appropriate type of read/write on a best effort basis.
Examples:
Using the YAML API:
cars:
type: polars.EagerPolarsDataset
file_format: parquet
filepath: s3://data/01_raw/company/cars.parquet
load_args:
low_memory: True
save_args:
compression: "snappy"
Using the Python API:
>>> import polars as pl
>>> from kedro_datasets.polars import EagerPolarsDataset
>>>
>>> data = pl.DataFrame({"col1": [1, 2], "col2": [4, 5], "col3": [5, 6]})
>>>
>>> dataset = EagerPolarsDataset(filepath=tmp_path / "test.parquet", file_format="parquet")
>>> dataset.save(data)
>>> reloaded = dataset.load()
>>> assert data.equals(reloaded)
identified by string matching on a best effort basis.
Parameters:
-
filepath(str) –Filepath in POSIX format to a file prefixed with a protocol like
s3://. If prefix is not provided,fileprotocol (local filesystem) will be used. The prefix should be any protocol supported byfsspec. Key assumption: The first argument of either load/save method points to a filepath/buffer/io type location. There are some read/write targets such as 'clipboard' or 'records' that will fail since they do not take a filepath like argument. -
file_format(str) –String which is used to match the appropriate load/save method on a best effort basis. For example if 'csv' is passed, the
polars.read_csvandpolars.DataFrame.write_csvmethods will be identified. An error will be raised unless there is at least one matchingread_<file_format>orwrite_<file_format>. -
load_args(dict[str, Any] | None, default:None) –Polars options for loading CSV files. Here you can find all available arguments: https://pola-rs.github.io/polars/py-polars/html/reference/io.html All defaults are preserved.
-
save_args(dict[str, Any] | None, default:None) –Polars options for saving files. Here you can find all available arguments: https://pola-rs.github.io/polars/py-polars/html/reference/io.html All defaults are preserved.
-
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. -
credentials(dict[str, Any] | None, default:None) –Credentials required to get access to the underlying filesystem. E.g. for
GCSFileSystemit should look like{"token": None}. -
fs_args(dict[str, Any] | None, default:None) –Extra arguments to pass into underlying filesystem class constructor (e.g.
{"project": "my-project"}forGCSFileSystem). -
metadata(dict[str, Any] | None, default:None) –Any arbitrary metadata. This is ignored by Kedro, but may be consumed by users or external plugins.
Raises: DatasetError: Will be raised if at least less than one appropriate read or write methods are identified.
Source code in kedro_datasets/polars/eager_polars_dataset.py
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 115 116 117 118 119 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 | |
_describe ¶
_describe()
Source code in kedro_datasets/polars/eager_polars_dataset.py
187 188 189 190 191 192 193 194 195 | |
_exists ¶
_exists()
Source code in kedro_datasets/polars/eager_polars_dataset.py
179 180 181 182 183 184 185 | |
_invalidate_cache ¶
_invalidate_cache()
Invalidate underlying filesystem caches.
Source code in kedro_datasets/polars/eager_polars_dataset.py
201 202 203 204 | |
_release ¶
_release()
Source code in kedro_datasets/polars/eager_polars_dataset.py
197 198 199 | |
load ¶
load()
Source code in kedro_datasets/polars/eager_polars_dataset.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 | |
save ¶
save(data)
Source code in kedro_datasets/polars/eager_polars_dataset.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |