maite.utils.validation.check_domain#

maite.utils.validation.check_domain(name, arg, *, lower=None, upper=None, incl_low=True, incl_up=True, lower_name='', upper_name='')[source]#

Check that an argument falls within [lower <=] arg [<= upper].

Parameters:
namestr

The argument’s name.

argComparable

The value to be checked.

lowerComparable|None

The lower bound of the domain. This bound is not checked if unspecified.

upperComparable|None

The upper bound of the domain. This bound is not checked if unspecified.

incl_lowbool, optional (default=True)

If True, the lower bound is inclusive.

incl_upbool, optional (default=True)

If True, the upper bound is inclusive.

lower_namestr = “”

If specified, includes the name of the lower bound in the error message.

upper_namestr = “”

If specified, includes the name of the upper bound in the error message.

Returns:
Comparable

The input value, arg, unchanged.

Raises:
InvalidArgument

arg does not satisfy the inequality.

Unsatisfiable

An internal assertion error when the provided domain bounds cannot be satisfied.

Examples

>>> from maite.utils.validation import check_domain
>>> try:
...     check_domain("x", 1, lower=20)
... except:
...     print("maite.errors.InvalidArgument: `x` must satisfy `20 <= x`.  Got: `1`.")
maite.errors.InvalidArgument: `x` must satisfy `20 <= x`.  Got: `1`.
>>> try:
...     check_domain("x", 1, lower=1, incl_low=False)
... except:
...     print("maite.errors.InvalidArgument: `x` must satisfy `1 < x`.  Got: `1`.")
maite.errors.InvalidArgument: `x` must satisfy `1 < x`.  Got: `1`.
>>> check_domain("x", 1, lower=1, incl_low=True) # ok
1
>>> check_domain("x", 0.0, lower=-10, upper=10)  # ok
0.0