albumentations.core.pydantic
Pydantic validation utilities for Albumentations. All validators here are tuple-only and reject scalar inputs. Scalar shorthand for sampling-range parameters has been removed across the public API.
Members
- functionnondecreasing
- functioncheck_range_bounds
nondecreasingfunction
nondecreasing(
value: tuple[Number, Number]
)Ensure the tuple is non-decreasing (`value[0] <= value[1]`); raise `ValueError` otherwise. Used as a Pydantic `AfterValidator` on ordered ranges. Args: value (tuple[Number, Number]): Tuple of two numeric values to validate. Returns: tuple[Number, Number]: The original tuple if valid. Raises: ValueError: If the first value is greater than the second value.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| value | tuple[Number, Number] | - | - |
check_range_boundsfunction
check_range_bounds(
min_val: Number,
max_val: Number | None,
min_inclusive: bool = True,
max_inclusive: bool = True
)Return a validator that ensures all values in a tuple are within min/max bounds (inclusive or exclusive). Use in Pydantic model field validators. Args: min_val (Number): Minimum allowed value. max_val (Number | None): Maximum allowed value. If None, only lower bound is checked. min_inclusive (bool): If True, min_val is inclusive (>=). If False, exclusive (>). max_inclusive (bool): If True, max_val is inclusive (<=). If False, exclusive (<). Returns: Callable[[tuple[T, ...] | None], tuple[T, ...] | None]: Validator function that checks if all values in tuple are within bounds. Returns None if input is None. Raises: ValueError: If any value in tuple is outside the allowed range Examples: >>> validator = check_range_bounds(0, 1) # For [0, 1] range >>> validator((0.1, 0.5)) # Valid 2D (0.1, 0.5) >>> validator((0.1, 0.5, 0.7)) # Valid 3D (0.1, 0.5, 0.7) >>> validator((1.1, 0.5)) # Raises ValueError - outside range >>> validator = check_range_bounds(0, 1, max_inclusive=False) # For [0, 1) range >>> validator((0, 1)) # Raises ValueError - 1 not included
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| min_val | Number | - | - |
| max_val | One of:
| - | - |
| min_inclusive | bool | True | - |
| max_inclusive | bool | True | - |