kedro.io.PickleLocalDataSet

class kedro.io.PickleLocalDataSet(filepath, backend='pickle', load_args=None, save_args=None, version=None)[source]

PickleLocalDataSet loads and saves a Python object to a local pickle file. The underlying functionality is supported by the pickle and joblib libraries, so it supports all allowed options for loading and saving pickle files.

Example:

from kedro.io import PickleLocalDataSet
import pandas as pd

dummy_data =  pd.DataFrame({'col1': [1, 2],
                            'col2': [4, 5],
                            'col3': [5, 6]})
data_set = PickleLocalDataSet(filepath="data.pkl",
                              backend='pickle',
                              load_args=None,
                              save_args=None)
data_set.save(dummy_data)
reloaded = data_set.load()
__init__(filepath, backend='pickle', load_args=None, save_args=None, version=None)[source]

Creates a new instance of PickleLocalDataSet pointing to a concrete filepath. PickleLocalDataSet can use two backends to serialise objects to disk:

pickle.dump: https://docs.python.org/3/library/pickle.html#pickle.dump

joblib.dump: https://pythonhosted.org/joblib/generated/joblib.dump.html

and it can use two backends to load serialised objects into memory:

pickle.load: https://docs.python.org/3/library/pickle.html#pickle.load

joblib.load: https://pythonhosted.org/joblib/generated/joblib.load.html

Joblib tends to exhibit better performance in case objects store NumPy arrays: http://gael-varoquaux.info/programming/new_low-overhead_persistence_in_joblib_for_big_data.html.

Parameters:
  • filepath (str) – path to a pkl file.
  • backend (str) – backend to use, must be one of [‘pickle’, ‘joblib’].
  • load_args (Optional[Dict[str, Any]]) – Options for loading pickle files. Refer to the help file of pickle.load or joblib.load for options.
  • save_args (Optional[Dict[str, Any]]) – Options for saving pickle files. Refer to the help file of pickle.dump or joblib.load for options.
  • version (Optional[Version]) – If specified, should be an instance of kedro.io.core.Version. If its load attribute is None, the latest version will be loaded. If its save attribute is None, save version will be autogenerated.
Raises:
  • ValueError – If ‘backend’ is not one of [‘pickle’, ‘joblib’].
  • ImportError – If ‘backend’ could not be imported.
Return type:

None

Methods

__init__(filepath[, backend, load_args, …]) Creates a new instance of PickleLocalDataSet pointing to a concrete filepath.
exists() Checks whether a data set’s output already exists by calling the provided _exists() method.
from_config(name, config[, load_version, …]) Create a data set instance using the configuration provided.
load() Loads data by delegation to the provided load method.
save(data) Saves data by delegation to the provided save method.

Attributes

BACKENDS