eogrow.utils.validators
Module defining common validators for schemas and validator wrappers
- eogrow.utils.validators.field_validator(field, validator_fun, allow_reuse=True, **kwargs)[source]
Sugared syntax for the validator decorator of pydantic
- Parameters:
field (str) –
validator_fun (Callable) –
allow_reuse (bool) –
kwargs (Any) –
- Return type:
classmethod
- eogrow.utils.validators.optional_field_validator(field, validator_fun, allow_reuse=True, **kwargs)[source]
Wraps the validator functions so that None is always a valid input and only calls the validator on values.
This allows re-use of validators e.g. if we have a validator for Path we can now use it for Optional[Path]. Because pydantic has a variable amount of arguments passed to the validator this function can only be used with validators that include **kwargs (or require all three arguments). For details on this behaviour consult the [validators documentation](https://pydantic-docs.helpmanual.io/usage/validators/).
- Parameters:
field (str) –
validator_fun (Callable) –
allow_reuse (bool) –
kwargs (Any) –
- Return type:
classmethod
- eogrow.utils.validators.ensure_exactly_one_defined(first_param, second_param, **kwargs)[source]
A validator (applied to second_param field) that makes sure only one of the two parameters is defined.
Make sure that the definition of second_param comes after first_param (in line-order).
- Parameters:
first_param (str) –
second_param (str) –
kwargs (Any) –
- Return type:
classmethod
- eogrow.utils.validators.ensure_defined_together(first_param, second_param, **kwargs)[source]
A validator (applied to second_param field) that makes sure that the two parameters are both (un)defined.
Make sure that the definition of second_param comes after first_param (in line-order).
- Parameters:
first_param (str) –
second_param (str) –
kwargs (Any) –
- Return type:
classmethod
- eogrow.utils.validators.ensure_storage_key_presence(key, **kwargs)[source]
A field validator that makes sure that the specified storage key is present in the storage structure.
- Parameters:
key (str) –
kwargs (Any) –
- Return type:
classmethod
- eogrow.utils.validators.parse_time_period(value)[source]
Allows parsing of preset options of shape [preset_kind, year] but that requires pre validation
- Parameters:
value (tuple[str, str]) –
- Return type:
Tuple[date, date]
- eogrow.utils.validators.validate_manager(value)[source]
Parse and validate schema describing a manager.
- Parameters:
value (dict) –
- Return type:
- pydantic model eogrow.utils.validators.BandSchema[source]
Bases:
BaseModel
Schema used in parsing DataCollection bands.
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
- Fields:
- field name: str [Required]
- field output_types: Tuple[type, ...] [Required]
- Validated by:
_parse_output_types
- field units: Tuple[Unit, ...] [Required]
- pydantic model eogrow.utils.validators.DataCollectionSchema[source]
Bases:
BaseModel
Schema used in parsing DataCollection objects. Extra parameters are passed to the definition as **params.
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
- Fields:
- field bands: None | str | Tuple[BandSchema, ...] = None
Name of predefined collection in Bands or custom specification via BandSchema.
- field metabands: None | str | Tuple[BandSchema, ...] = None
Name of predefined collection in MetaBands or custom specification via BandSchema.
- field name: str = 'Name of the data collection. When defining BYOC collections use `BYOC_` prefix and for Batch collections use `BATCH_` to auto-generate fields with `define_byoc` or `define_batch`.'
- eogrow.utils.validators.parse_data_collection(value)[source]
Validates and parses the data collection.
If a string is given, then it tries to fetch a pre-defined collection. Otherwise it constructs a new collection according to the prefix of the name (BYOC_ prefix to use define_byoc and BATCH_ to use define_batch).
- Parameters:
value (str | dict | DataCollection) –
- Return type:
DataCollection
- eogrow.utils.validators.restrict_types(allowed_feature_types)[source]
Validates a field representing a feature, where it restricts the possible feature types.
- Parameters:
allowed_feature_types (Iterable[FeatureType] | Callable[[FeatureType], bool]) –
- Return type:
Callable[[Tuple[FeatureType, str]], Tuple[FeatureType, str]]