brain_pipe.save.base.Save

class Save(clear_output=False, overwrite=False, *args, **kwargs)

Bases: PipelineStep, ABC

Base class for all save steps.

__init__(clear_output=False, overwrite=False, *args, **kwargs)

Create a new Save instance.

Parameters:
  • clear_output (bool) – Whether to clear the output data_dict after saving. This can save space when save is the last step in a pipeline.

  • overwrite (bool) – Whether to overwrite existing files.

  • args (Sequence[Any]) – Additional positional arguments for PipelineStep.

  • kwargs (Dict[Any, Any]) – Additional keyword arguments for PipelineStep.

Methods

__init__([clear_output, overwrite])

Create a new Save instance.

is_already_done(data_dict)

Check if the step was already done.

is_reloadable(data_dict)

Check if the data can be reloaded.

parse_dict_keys(key[, name, ...])

Parse a key or a sequence of keys.

reload(data_dict)

Reload the data.

abstract is_already_done(data_dict: Dict[str, Any]) bool

Check if the step was already done.

Parameters:

data_dict (Dict[str, Any]) – The data dict containing the data to save.

Returns:

True if the step was already done, False otherwise.

Return type:

bool

abstract is_reloadable(data_dict: Dict[str, Any]) bool

Check if the data can be reloaded.

Parameters:

data_dict (Dict[str, Any]) – The data dict containing the data to save.

Returns:

True if the data can be reloaded, False otherwise.

Return type:

bool

parse_dict_keys(key: str | Sequence[str] | Mapping[str, str], name='key', require_ordered_dict=False) OrderedDict[str, str]

Parse a key or a sequence of keys.

Parameters:
  • key (Union[str, Sequence[str], Mapping[str,str]]) – A key or a sequence of keys.

  • name (str) – The name of the key. Used for error messages.

  • require_ordered_dict (bool) – If True, the key must be an OrderedDict. If False, the key can also be an ordinary dict.

Returns:

A mapping of input keys to output keys.

Return type:

OrderedDict[str, str]

Raises:

TypeError – If the key is not a string, a sequence of strings or a mapping of strings. If the key is a mapping but require_ordered_dict is True and the mapping is not an OrderedDict.

abstract reload(data_dict: Dict[str, Any]) Dict[str, Any]

Reload the data.

Parameters:

data_dict (Dict[str, Any]) – The data dict containing the data to save.

Returns:

The data dict containing the reloaded data.

Return type:

Dict[str, Any]