MetaMixin#

class scikitplot.annoy.MetaMixin[source]#

Mixin that exports and restores index metadata.

The concrete class (or its backend) must implement:

  • get_params(deep: bool = ...) -> Mapping[str, Any]

  • set_params(**params) -> Self

Optional backend methods:

  • info() -> Mapping[str, Any] | None

The concrete class must define:

  • _META_SCHEMA_VERSION (int)

Notes

from_metadata(..., load=True) optionally loads the on-disk index when the params mapping contains on_disk_path. This is a deterministic behavior controlled only by explicit fields.

classmethod from_json(path, *, load=True)[source]#

Load metadata from JSON and construct an index.

Parameters:
Return type:

Self

classmethod from_metadata(metadata, *, load=True)[source]#

Construct an index from a metadata payload.

Parameters:
metadataMapping[str, Any]

Payload as produced by to_metadata.

loadbool, default=True

If True and params['on_disk_path'] is present, attempt to load the index into the returned object via backend load.

Returns:
indexSelf

Newly constructed index.

Raises:
TypeError

If input types are invalid.

ValueError

If required fields are missing or invalid.

AttributeError

If backend set_params/load are missing when required.

Parameters:
Return type:

Self

classmethod from_yaml(path, *, load=True)[source]#

Load metadata from YAML and construct an index (requires PyYAML).

Parameters:
Return type:

Self

to_json(path=None, *, indent=2, sort_keys=True, ensure_ascii=False, include_info=True, strict=True)[source]#

Serialize to_metadata to JSON.

Parameters:
path

If provided, write the JSON to this path atomically.

indent

Indentation level passed to json.dumps.

sort_keys

If True, sort keys for stable output.

ensure_ascii

If True, escape non-ASCII characters.

include_info, strict

Forwarded to to_metadata.

Returns:
json_str

JSON representation of the metadata.

Parameters:
Return type:

str

to_metadata(*, include_info=True, strict=True)[source]#

Export a serializable metadata payload.

Parameters:
include_info

If True, include a backend-provided info() mapping when available.

strict

If True, backend failures in optional info() propagation raise.

Returns:
metadata

A JSON/YAML-serializable mapping containing configuration parameters and optional info.

Raises:
RuntimeError

If _META_SCHEMA_VERSION is missing on the concrete class.

TypeError

If backend get_params does not return a mapping.

AttributeError

If the backend does not implement get_params.

Parameters:
Return type:

IndexMetadata

to_yaml(path=None, *, include_info=True, strict=True)[source]#

Serialize to_metadata to YAML (requires PyYAML).

Parameters:
Return type:

str