nirs4all.data.schema.validation.validators module

Validators for dataset configuration.

This module provides validation logic for dataset configurations, checking for consistency, required fields, file existence, and other rules.

class nirs4all.data.schema.validation.validators.ConfigValidator(check_file_existence: bool = False, custom_validators: List[Callable] | None = None)[source]

Bases: object

Validator for dataset configurations.

Provides validation rules and methods for checking dataset configurations. Supports both legacy and new format configurations.

Example

```python validator = ConfigValidator() result = validator.validate(config_dict) if not result.is_valid:

for error in result.errors:

print(f”Error: {error}”)

```

validate(config: Dict[str, Any]) ValidationResult[source]

Validate a configuration dictionary.

Parameters:

config – Configuration dictionary to validate.

Returns:

ValidationResult with errors, warnings, and normalized config.

class nirs4all.data.schema.validation.validators.ValidationError(code: str, message: str, field: str | None = None, value: Any = None, suggestion: str | None = None)[source]

Bases: object

Represents a validation error.

code

Error code for programmatic handling.

Type:

str

message

Human-readable error message.

Type:

str

field

The configuration field that caused the error.

Type:

str | None

value

The value that caused the error.

Type:

Any

suggestion

Optional suggestion for fixing the error.

Type:

str | None

code: str
field: str | None = None
message: str
suggestion: str | None = None
value: Any = None
class nirs4all.data.schema.validation.validators.ValidationResult(is_valid: bool, errors: ~typing.List[~nirs4all.data.schema.validation.validators.ValidationError] = <factory>, warnings: ~typing.List[~nirs4all.data.schema.validation.validators.ValidationWarning] = <factory>, normalized_config: ~typing.Dict[str, ~typing.Any] | None = None)[source]

Bases: object

Result of configuration validation.

is_valid

Whether the configuration is valid (no errors).

Type:

bool

errors

List of validation errors.

Type:

List[nirs4all.data.schema.validation.validators.ValidationError]

warnings

List of validation warnings.

Type:

List[nirs4all.data.schema.validation.validators.ValidationWarning]

normalized_config

The validated and normalized configuration.

Type:

Dict[str, Any] | None

errors: List[ValidationError]
is_valid: bool
normalized_config: Dict[str, Any] | None = None
raise_if_invalid() None[source]

Raise ValueError if configuration is invalid.

warnings: List[ValidationWarning]
class nirs4all.data.schema.validation.validators.ValidationWarning(code: str, message: str, field: str | None = None)[source]

Bases: object

Represents a validation warning (non-fatal issue).

code

Warning code for programmatic handling.

Type:

str

message

Human-readable warning message.

Type:

str

field

The configuration field that caused the warning.

Type:

str | None

code: str
field: str | None = None
message: str
nirs4all.data.schema.validation.validators.validate_config(config: Dict[str, Any], check_file_existence: bool = False) ValidationResult[source]

Convenience function to validate a configuration.

Parameters:
  • config – Configuration dictionary to validate.

  • check_file_existence – Whether to check if referenced files exist.

Returns:

ValidationResult with errors, warnings, and normalized config.