ns_sdn.exceptions#

The error hierarchy every module raises from.

Three subclasses, one per kind of fix. DimensionError means the geometry of an input is wrong (reshape the data); SpecificationError means the content of a choice is wrong (change the argument); NumericalError means the arithmetic could not be carried out (look at the numbers). Each also derives from the matching builtin, so code written against ValueError and RuntimeError keeps working, and all share NSSDNError, so one except clause catches anything the package raises. The shape mirrors cultivars.exceptions so a caller handling one package’s errors handles the other’s without a second clause.

Every message names the argument, states the rule it broke and quotes the offending value, in that order, so a traceback is enough to fix the call: k must be at least 1; got 0.

Exception

Builtin base

Raised when

DimensionError

ValueError

A series is not one-dimensional or is too short; covariates, a time grid or future covariates have the wrong length or width.

SpecificationError

ValueError

An option is outside its Literal; a count, rate, threshold or seed is of the wrong type or sign; a schedule or penalties record is malformed; a time grid is not strictly increasing.

NumericalError

RuntimeError

Data contain nan or inf; the training loss becomes non-finite.

Example

>>> import numpy as np
>>> from ns_sdn.spectral_decomposition import NSSDN
>>> try:
...     NSSDN(np.arange(50.0), k=0)
... except NSSDNError as error:
...     print(type(error).__name__)
SpecificationError

The builtin bases are kept, so generic handlers still work:

>>> issubclass(DimensionError, ValueError), issubclass(NumericalError, RuntimeError)
(True, True)
>>> try:
...     NSSDN(np.ones((4, 2)))
... except ValueError as error:
...     print(error)
endog must be one-dimensional; got shape (4, 2).

Exceptions#

DimensionError

An input has the wrong rank, length, or alignment.

NSSDNError

Base class for every exception raised by ns-sdn.

NumericalError

A computation could not be carried out: non-finite data, a diverged fit.

SpecificationError

A specification choice is outside its admissible set.