Skip to content

openscm_calibration.exceptions#

Exceptions that are used throughout

Classes:

Name Description
MismatchLengthError

Raised when an object should have the same length as something else, but doesn't

MissingOptionalDependencyError

Raised when an optional dependency is missing

MissingValueError

Raised when a sequence is missing a value(s) that we expect it to have

NotExpectedAllSameValueError

Raised when the values are not all the same expected value

NotExpectedValueError

Raised when the value is not what we expect

MismatchLengthError #

Bases: ValueError

Raised when an object should have the same length as something else, but doesn't

Methods:

Name Description
__init__

Initialise the error

Source code in src/openscm_calibration/exceptions.py
class MismatchLengthError(ValueError):
    """
    Raised when an object should have the same length as something else, but doesn't
    """

    def __init__(
        self, name: str, length: int, expected_name: Any, expected_length: int
    ) -> None:
        """
        Initialise the error

        Parameters
        ----------
        name
            The name of the thing being referenced (variable, attribute etc.)

        length
            The length of the thing being referenced

        expected_name
            The name of the thing we expect to match

        expected_length
            The expected length of the thing ``name`` references
        """
        error_msg = (
            f"``{name}`` has length {length}, it should have length "
            f"{expected_length}, the same as ``{expected_name}``"
        )
        super().__init__(error_msg)

__init__ #

__init__(
    name: str,
    length: int,
    expected_name: Any,
    expected_length: int,
) -> None

Initialise the error

Parameters:

Name Type Description Default
name str

The name of the thing being referenced (variable, attribute etc.)

required
length int

The length of the thing being referenced

required
expected_name Any

The name of the thing we expect to match

required
expected_length int

The expected length of the thing name references

required
Source code in src/openscm_calibration/exceptions.py
def __init__(
    self, name: str, length: int, expected_name: Any, expected_length: int
) -> None:
    """
    Initialise the error

    Parameters
    ----------
    name
        The name of the thing being referenced (variable, attribute etc.)

    length
        The length of the thing being referenced

    expected_name
        The name of the thing we expect to match

    expected_length
        The expected length of the thing ``name`` references
    """
    error_msg = (
        f"``{name}`` has length {length}, it should have length "
        f"{expected_length}, the same as ``{expected_name}``"
    )
    super().__init__(error_msg)

MissingOptionalDependencyError #

Bases: ImportError

Raised when an optional dependency is missing

For example, plotting dependencies like seaborn

Methods:

Name Description
__init__

Initialise the error

Source code in src/openscm_calibration/exceptions.py
class MissingOptionalDependencyError(ImportError):
    """
    Raised when an optional dependency is missing

    For example, plotting dependencies like seaborn
    """

    def __init__(self, callable_name: str, requirement: str) -> None:
        """
        Initialise the error

        Parameters
        ----------
        callable_name
            The name of the callable that requires the dependency

        requirement
            The name of the requirement
        """
        error_msg = f"`{callable_name}` requires {requirement} to be installed"
        super().__init__(error_msg)

__init__ #

__init__(callable_name: str, requirement: str) -> None

Initialise the error

Parameters:

Name Type Description Default
callable_name str

The name of the callable that requires the dependency

required
requirement str

The name of the requirement

required
Source code in src/openscm_calibration/exceptions.py
def __init__(self, callable_name: str, requirement: str) -> None:
    """
    Initialise the error

    Parameters
    ----------
    callable_name
        The name of the callable that requires the dependency

    requirement
        The name of the requirement
    """
    error_msg = f"`{callable_name}` requires {requirement} to be installed"
    super().__init__(error_msg)

MissingValueError #

Bases: ValueError

Raised when a sequence is missing a value(s) that we expect it to have

Methods:

Name Description
__init__

Initialise the error

Source code in src/openscm_calibration/exceptions.py
class MissingValueError(ValueError):
    """
    Raised when a sequence is missing a value(s) that we expect it to have
    """

    def __init__(self, name: str, vals: Sequence[Any], missing_vals: Any) -> None:
        """
        Initialise the error

        Parameters
        ----------
        name
            The name of the thing being referenced (variable, attribute etc.)

        vals
            The values in ``name``

        missing_vals
            The value(s) that are missing
        """
        error_msg = (
            f"``{name}`` is missing values: ``{missing_vals}``. "
            f"Available values: ``{vals}``"
        )
        super().__init__(error_msg)

__init__ #

__init__(
    name: str, vals: Sequence[Any], missing_vals: Any
) -> None

Initialise the error

Parameters:

Name Type Description Default
name str

The name of the thing being referenced (variable, attribute etc.)

required
vals Sequence[Any]

The values in name

required
missing_vals Any

The value(s) that are missing

required
Source code in src/openscm_calibration/exceptions.py
def __init__(self, name: str, vals: Sequence[Any], missing_vals: Any) -> None:
    """
    Initialise the error

    Parameters
    ----------
    name
        The name of the thing being referenced (variable, attribute etc.)

    vals
        The values in ``name``

    missing_vals
        The value(s) that are missing
    """
    error_msg = (
        f"``{name}`` is missing values: ``{missing_vals}``. "
        f"Available values: ``{vals}``"
    )
    super().__init__(error_msg)

NotExpectedAllSameValueError #

Bases: ValueError

Raised when the values are not all the same expected value

Methods:

Name Description
__init__

Initialise the error

Source code in src/openscm_calibration/exceptions.py
class NotExpectedAllSameValueError(ValueError):
    """
    Raised when the values are not all the same expected value
    """

    def __init__(self, ref_name: str, expected_val: Any) -> None:
        """
        Initialise the error

        Parameters
        ----------
        ref_name
            The name of the thing being referenced (variable, attribute etc.)

        expected_val
            The value we expected all elements of ``ref_name`` to have
        """
        error_msg = f"All values in ``{ref_name}`` should be ``{expected_val}``"
        super().__init__(error_msg)

__init__ #

__init__(ref_name: str, expected_val: Any) -> None

Initialise the error

Parameters:

Name Type Description Default
ref_name str

The name of the thing being referenced (variable, attribute etc.)

required
expected_val Any

The value we expected all elements of ref_name to have

required
Source code in src/openscm_calibration/exceptions.py
def __init__(self, ref_name: str, expected_val: Any) -> None:
    """
    Initialise the error

    Parameters
    ----------
    ref_name
        The name of the thing being referenced (variable, attribute etc.)

    expected_val
        The value we expected all elements of ``ref_name`` to have
    """
    error_msg = f"All values in ``{ref_name}`` should be ``{expected_val}``"
    super().__init__(error_msg)

NotExpectedValueError #

Bases: ValueError

Raised when the value is not what we expect

This is a very verbose version of an assertion error

Methods:

Name Description
__init__

Initialise the error

Source code in src/openscm_calibration/exceptions.py
class NotExpectedValueError(ValueError):
    """
    Raised when the value is not what we expect

    This is a very verbose version of an assertion error
    """

    def __init__(self, ref_name: str, val: Any, expected_val: Any) -> None:
        """
        Initialise the error

        Parameters
        ----------
        ref_name
            The name of the thing being referenced (variable, attribute etc.)

        val
            The value of ``ref_name``

        expected_val
            The value we expected
        """
        error_msg = f"``{ref_name}`` must have value: {expected_val}, received: {val}"
        super().__init__(error_msg)

__init__ #

__init__(
    ref_name: str, val: Any, expected_val: Any
) -> None

Initialise the error

Parameters:

Name Type Description Default
ref_name str

The name of the thing being referenced (variable, attribute etc.)

required
val Any

The value of ref_name

required
expected_val Any

The value we expected

required
Source code in src/openscm_calibration/exceptions.py
def __init__(self, ref_name: str, val: Any, expected_val: Any) -> None:
    """
    Initialise the error

    Parameters
    ----------
    ref_name
        The name of the thing being referenced (variable, attribute etc.)

    val
        The value of ``ref_name``

    expected_val
        The value we expected
    """
    error_msg = f"``{ref_name}`` must have value: {expected_val}, received: {val}"
    super().__init__(error_msg)