Commands¶
Contains a few more sophisticated commands that are usually accessed directly inside configs.
- dpipe.commands.populate(path: Union[Path, str], func: Callable, *args, **kwargs)[source]¶
Call
func
withargs
andkwargs
ifpath
doesn’t exist.Examples
>>> populate('metrics.json', save_metrics, targets, predictions) # if `metrics.json` doesn't exist, the following call will be performed: >>> save_metrics(targets, predictions)
- Raises
FileNotFoundError – if after calling
func
thepath
still doesn’t exist.:
- dpipe.commands.lock_dir(folder: Union[Path, str] = '.', lock: str = '.lock')[source]¶
Lock the given
folder
by generating a special lock file -lock
.- Raises
FileExistsError – if
lock
already exists, i.e. the folder is already locked.:
- dpipe.commands.load_from_folder(path: ~typing.Union[~pathlib.Path, str], loader=<function load>, ext='.npy')[source]¶
Yields (id, object) pairs loaded from
path
.
- dpipe.commands.map_ids_to_disk(func: ~typing.Callable[str, object], ids: ~typing.Iterable[str], output_path: str, exist_ok: bool = False, save: ~typing.Callable = <function save>, ext: str = '.npy')[source]¶
Apply
func
to each id fromids
and save each output tooutput_path
usingsave
. Ifexist_ok
is True the existing files will be ignored, otherwise an exception is raised.
- dpipe.commands.predict(ids, output_path, load_x, predict_fn, exist_ok=False, save: ~typing.Callable = <function save>, ext='.npy')[source]¶