culebra.checker
module¶
Checker functions for different data types.
Functions¶
- check_str(value: str, name: str, valid_chars: str | None = None, invalid_chars: str | None = None) str ¶
Check if the given value is a valid string.
- Parameters:
- Returns:
A valid string
- Return type:
- Raises:
TypeError – If value is not a string
- 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 valuename (
str
) – The value namegt (
Real
, optional) – Inferior limit. If provided, value must be greater than gtge (
Real
, optional) – Inferior limit. If provided, value must be greater than or equal to gelt (
Real
, optional) – Superior limit. If provided, value must be lower than ltle (
Real
, optional) – 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_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 valuename (
str
) – The value namegt (
int
, optional) – Inferior limit. If provided, value must be greater than gtge (
int
, optional) – Inferior limit. If provided, value must be greater than or equal to gelt (
int
, optional) – Superior limit. If provided, value must be lower than ltle (
int
, optional) – Superior limit. If provided, value must be lower than or equal to lene (
int
, optional) – 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_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 valuename (
str
) – The value namegt (
float
, optional) – Inferior limit. If provided, value must be greater than gtge (
float
, optional) – Inferior limit. If provided, value must be greater than or equal to gelt (
float
, optional) – Superior limit. If provided, value must be lower than ltle (
float
, optional) – 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_instance(value: object, name: str, cls: type) object ¶
Check if the given value is an instance of cls.
- check_subclass(value: type, name: str, cls: type) type ¶
Check if the given value is subclass of cls.
- 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_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:
A
list
- Raises:
ValueError – If the number of items in the sequence does not match size
ValueError – If any item fails the item_checker function
- check_filename(value: str, 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_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) str ¶
Check if the given values define a correct two-dimensional matrix.
- Parameters:
values – The values
name (
str
) – The value namedtype (
str
ortype
) – Data type. If provided, all values must be of this type, optionalsquare (
bool
) – IfTrue
the matrix is required to be square. Defaults toFalse
gt (
float
, optional) – Inferior limit. If provided, all values must be greater than gtge (
float
, optional) – Inferior limit. If provided, all values must be greater than or equal to gelt (
float
, optional) – Superior limit. If provided, all values must be lower than ltle (
float
, optional) – 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