milia.core.exceptions#

Milia exception hierarchy and the optional-dependency guard.

Functions

require(package, extra)

Raise a helpful error if an optional dependency is missing.

Exceptions

ConfigurationError

Raised when a configuration is invalid or incompatible.

MiliaError

Base class for all milia exceptions.

MissingExtraError

Raised when an optional dependency is not installed.

NotFittedError

Raised when an estimator is used before it is fitted.

exception milia.core.exceptions.ConfigurationError#

Bases: MiliaError, ValueError

Raised when a configuration is invalid or incompatible.

Examples

>>> from milia import get
>>> get("detector", "nope")
Traceback (most recent call last):
...
milia.core.exceptions.ConfigurationError: no detector named 'nope'; ...
exception milia.core.exceptions.MissingExtraError#

Bases: MiliaError, ImportError

Raised when an optional dependency is not installed.

Examples

>>> require("definitely_not_a_package", "foo")
Traceback (most recent call last):
...
milia.core.exceptions.MissingExtraError: 'definitely_not_a_package' is required ...
exception milia.core.exceptions.NotFittedError#

Bases: MiliaError, NotFittedError

Raised when an estimator is used before it is fitted.

Subclasses scikit-learn’s own NotFittedError, so code that catches the scikit-learn exception also catches this one.

Examples

>>> from sklearn.exceptions import NotFittedError as Sklearn
>>> issubclass(NotFittedError, Sklearn)
True
exception milia.core.exceptions.MiliaError#

Bases: Exception

Base class for all milia exceptions.

Examples

>>> issubclass(ConfigurationError, MiliaError)
True
milia.core.exceptions.require(package, extra)#

Raise a helpful error if an optional dependency is missing.

Called at the top of every module that needs an optional package, before the package itself is imported, so the user is told which extra to install.

Parameters:
  • package (str) – Importable name of the package, e.g. "tslearn".

  • extra (str) – The milia extra that provides it, e.g. "ts".

Raises:

MissingExtraError – If package cannot be imported.

Return type:

None

Examples

>>> require("numpy", "core")