culebra.checker module¶
Checker functions for different data types.
Functions¶
- check_filename(value: str | PathLike, name: str, ext: str | None = None) str¶
Check if the given value is a valid filename.
- Parameters:
- Returns:
A valid filename
- Return type:
- Raises:
TypeError – If value is not a valid file name
ValueError – If value does not meet the constraints
ValueError – If ext does not begin with a dot
- check_float(value: float, name: str, gt: float | None = None, ge: float | None = None, lt: float | None = None, le: float | None = None) float¶
Check if the given value is a valid float.
- Parameters:
value (float) – The value
name (str) – The value name
gt (float) – Inferior limit. If provided, value must be greater than gt
ge (float) – Inferior limit. If provided, value must be greater than or equal to ge
lt (float) – Superior limit. If provided, value must be lower than lt
le (float) – Superior limit. If provided, value must be lower than or equal to le
- Returns:
A valid float
- Return type:
- Raises:
TypeError – If value is not a floating point number
- check_func_params(value: dict[str, Any], name: str) dict[str, Any]¶
Check if the given value is a valid set of function parameters.
- Parameters:
- Raises:
TypeError – If value is not a dictionary
ValueError – If the keys in value are not strings
- check_instance(value: object, name: str, cls: type) object¶
Check if the given value is an instance of cls.
- check_int(value: int, name: str, gt: int | None = None, ge: int | None = None, lt: int | None = None, le: int | None = None, ne: int | None = None) int¶
Check if the given value is a valid integer.
- Parameters:
value (int) – The value
name (str) – The value name
gt (int) – Inferior limit. If provided, value must be greater than gt
ge (int) – Inferior limit. If provided, value must be greater than or equal to ge
lt (int) – Superior limit. If provided, value must be lower than lt
le (int) – Superior limit. If provided, value must be lower than or equal to le
ne (int) – Not equal. If provided, value can not be equal to ne
- Returns:
A valid integer
- Return type:
- Raises:
TypeError – If value is not an integer number
ValueError – If value does not meet any imposed constraint
- check_limits(value: Real, name: str, gt: Real | None = None, ge: Real | None = None, lt: Real | None = None, le: Real | None = None) Real¶
Check if the given value meets the limits.
- Parameters:
value (Real) – The value
name (str) – The value name
gt (Real) – Inferior limit. If provided, value must be greater than gt
ge (Real) – Inferior limit. If provided, value must be greater than or equal to ge
lt (Real) – Superior limit. If provided, value must be lower than lt
le (Real) – Superior limit. If provided, value must be lower than or equal to le
- Returns:
A valid integer
- Return type:
- Raises:
ValueError – If value does not meet any imposed limit
- check_matrix(values: Sequence[Sequence[object], ...], name: str, dtype: str | type | None = None, square: bool | None = False, gt: float | None = None, ge: float | None = None, lt: float | None = None, le: float | None = None) ndarray¶
Check if the given values define a correct two-dimensional matrix.
- Parameters:
name (str) – The value name
dtype (str | type) – Data type. If provided, all values must be of this type, optional
square (bool) – If
Truethe matrix is required to be square. Defaults toFalsegt (float) – Inferior limit. If provided, all values must be greater than gt
ge (float) – Inferior limit. If provided, all values must be greater than or equal to ge
lt (float) – Superior limit. If provided, all values must be lower than lt
le (float) – Superior limit. If provided, all values must be lower than or equal to le
- Returns:
A valid float
- Return type:
- Returns:
A valid matrix
- Return type:
- Raises:
TypeError – If values is not an array-like object
ValueError – If values do not conform the provided dtype
ValueError – If values has not an homogeneous shape
ValueError – If values has not two dimensions
ValueError – If values does not meet any imposed limit
- check_sequence(seq: Sequence[Any], name: str, size: int | None = None, item_checker: Callable[[Any, str], Any] | None = None) list[Any]¶
Check a sequence of items.
- Parameters:
- Returns:
The checked sequence
- Return type:
- Raises:
ValueError – If the number of items in the sequence does not match size
ValueError – If any item fails the item_checker function

