Checklist is a set of validation checks and a few addition settings. Let's create a checklist:
from frictionless import Checklist, checks
checklist = Checklist(checks=[checks.row_constraint(formula='id > 1')])
print(checklist)
{'checks': [{'type': 'row-constraint', 'formula': 'id > 1'}]}
The Check concept is a part of the Validation API. You can create a custom Check to be used as part of resource or package validation.
from frictionless import Check, errors
class duplicate_row(Check):
code = "duplicate-row"
Errors = [errors.DuplicateRowError]
def __init__(self, descriptor=None):
super().__init__(descriptor)
self.__memory = {}
def validate_row(self, row):
text = ",".join(map(str, row.values()))
hash = hashlib.sha256(text.encode("utf-8")).hexdigest()
match = self.__memory.get(hash)
if match:
note = 'the same as row at position "%s"' % match
yield errors.DuplicateRowError.from_row(row, note=note)
self.__memory[hash] = row.row_position
# Metadata
metadata_profile = { # type: ignore
"type": "object",
"properties": {},
}
It's usual to create a custom Error along side with a Custom Check.
Checklist representation. A class that combines multiple checks to be applied while validating a resource or package.
(*, name: Optional[str] = None, title: Optional[str] = None, description: Optional[str] = None, checks: List[Check] = NOTHING, pick_errors: List[str] = NOTHING, skip_errors: List[str] = NOTHING) -> None
A short name(preferably human-readable) for the Checklist. This MUST be lower-case and contain only alphanumeric characters along with "-" or "_".
Optional[str]
Type of the object
ClassVar[Union[str, None]]
A human-readable title for the Checklist.
Optional[str]
A detailed description for the Checklist.
Optional[str]
List of checks to be applied during validation such as "deviated-cell", "required-value" etc.
List[Check]
Specify the errors names to be picked while validation such as "sha256-count", "byte-count". Errors other than specified will be ignored.
List[str]
Specify the errors names to be skipped while validation such as "sha256-count", "byte-count". Other errors will be included.
List[str]
Add new check to the schema
(check: Check) -> None
Remove all the checks
() -> None
Get check by type
(type: str) -> Check
Check if a check is present
(type: str) -> bool
Remove check by type
(type: str) -> Check
Set check by type
(check: Check) -> Optional[Check]
Check representation. A base class for all the checks. To add a new custom check, it has to be derived from this class.
(*, name: Optional[str] = None, title: Optional[str] = None, description: Optional[str] = None) -> None
A short url-usable (and preferably human-readable) name. This MUST be lower-case and contain only alphanumeric characters along with “.”, “_” or “-” characters.
Optional[str]
A short name(preferably human-readable) for the Check. This MUST be lower-case and contain only alphanumeric characters along with "-" or "_".
ClassVar[str]
A human-readable title for the Check.
Optional[str]
A detailed description for the Check.
Optional[str]
List of errors that are being used in the Check.
ClassVar[List[Type[Error]]]
Resource
Connect to the given resource
(resource: Resource)
Called to validate the resource before closing
() -> Iterable[Error]
Called to validate the given row (on every row)
(row: Row) -> Iterable[Error]
Called to validate the resource after opening
() -> Iterable[Error]