Edit page in Livemark
(2022-09-19 18:33)

Checklist Class

Creating Checklist

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'}]}

Validation Checks

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 usuall to create a custom Error along side with a Custom Check.

Reference

Checklist (class)

Check (class)

Checklist (class)

Checklist representation

Signature

(*, 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

Parameters

  • name (Optional[str])
  • title (Optional[str])
  • description (Optional[str])
  • checks (List[Check])
  • pick_errors (List[str])
  • skip_errors (List[str])

checklist.name (property)

NOTE: add docs

Signature

Optional[str]

checklist.title (property)

NOTE: add docs

Signature

Optional[str]

checklist.description (property)

NOTE: add docs

Signature

Optional[str]

checklist.checks (property)

NOTE: add docs

Signature

List[Check]

checklist.pick_errors (property)

NOTE: add docs

Signature

List[str]

checklist.skip_errors (property)

NOTE: add docs

Signature

List[str]

checklist.add_check (method)

Add new check to the schema

Signature

(check: Check) -> None

Parameters

  • check (Check)

checklist.clear_checks (method)

Remove all the checks

Signature

() -> None

checklist.get_check (method)

Get check by type

Signature

(type: str) -> Check

Parameters

  • type (str)

checklist.has_check (method)

Check if a check is present

Signature

(type: str) -> bool

Parameters

  • type (str)

checklist.remove_check (method)

Remove check by type

Signature

(type: str) -> Check

Parameters

  • type (str)

checklist.set_check (method)

Set check by type

Signature

(check: Check) -> Optional[Check]

Parameters

  • check (Check)

Check (class)

Check representation.

Signature

(*, title: Optional[str] = None, description: Optional[str] = None) -> None

Parameters

  • title (Optional[str])
  • description (Optional[str])

check.type (property)

NOTE: add docs

Signature

ClassVar[str]

check.Errors (property)

NOTE: add docs

Signature

ClassVar[List[Type[Error]]]

check.title (property)

NOTE: add docs

Signature

Optional[str]

check.description (property)

NOTE: add docs

Signature

Optional[str]

check.resource (property)

Signature

Resource

check.connect (method)

Connect to the given resource

Signature

(resource: Resource)

Parameters

  • resource (Resource): data resource

check.validate_end (method)

Called to validate the resource before closing

Signature

() -> Iterable[Error]

check.validate_row (method)

Called to validate the given row (on every row)

Signature

(row: Row) -> Iterable[Error]

Parameters

  • row (Row): table row

check.validate_start (method)

Called to validate the resource after opening

Signature

() -> Iterable[Error]

It's a beta version of Frictionless Framework (v5). Read Frictionless Framework (v4) docs for a version that is currently installed by default by pip.