PickleIOMixin#

class scikitplot.annoy.PickleIOMixin[source]#

Mixin adding explicit Python-object to pickling dump/load helpers.

Notes

This mixin serializes the Python object using a pickle-family backend. It should not be used as a substitute for Annoy’s native index persistence. Prefer composing with PickleMixin if you need Annoy-aware, deterministic object serialization.

dump_pickle(path, *, backend='joblib', **kwargs)[source]#

Serialize this object to a binary file.

Parameters:
pathstr or os.PathLike

Destination path.

backend{‘pickle’, ‘cloudpickle’, ‘joblib’}, default=’joblib’

Backend used for serialization.

**kwargs

Extra keyword arguments forwarded to the backend dumper.

  • joblib: forwarded to joblib.dump (e.g. compress=3)

  • pickle: currently unused (kept for forwards compatibility)

  • cloudpickle: currently unused (kept for forwards compatibility)

  • pickle / cloudpickle: accepts protocol=int to control the pickle protocol.

Raises:
ValueError

If backend is unsupported.

OSError

If the file cannot be written.

Parameters:
Return type:

None

classmethod load_pickle(path, *, backend='joblib', **kwargs)[source]#

Load an object from a binary file.

Parameters:
pathstr or os.PathLike

File path to read.

backend{‘pickle’, ‘cloudpickle’, ‘joblib’}, default=’joblib’

Backend used for deserialization.

**kwargs

Extra keyword arguments forwarded to the backend loader.

  • joblib: forwarded to joblib.load

  • pickle: currently unused (kept for forwards compatibility)

  • cloudpickle: currently unused (kept for forwards compatibility)

Returns:
objSelf

Deserialized object. Ensures the returned instance is of type cls.

Raises:
ValueError

If backend is unsupported.

TypeError

If the deserialized object is not an instance of cls.

FileNotFoundError

If the file does not exist.

Parameters:
Return type:

Self

Notes

All supported backends can execute arbitrary code during loading. Do not load untrusted data.