Edit page in Livemark
(2024-11-07 15:17)

Report Class

Validation Report

All the validate functions return the Validation Report. It's an unified object containing information about a validation: source details, found error, etc. Let's explore a report:

from frictionless import validate

report = validate('capital-invalid.csv', pick_errors=['duplicate-label'])
print(report)
{'valid': False,
 'stats': {'tasks': 1, 'errors': 1, 'warnings': 0, 'seconds': 0.007},
 'warnings': [],
 'errors': [],
 'tasks': [{'name': 'capital-invalid',
            'type': 'table',
            'valid': False,
            'place': 'capital-invalid.csv',
            'labels': ['id', 'name', 'name'],
            'stats': {'errors': 1,
                      'warnings': 0,
                      'seconds': 0.007,
                      'md5': 'dcdeae358cfd50860c18d953e021f836',
                      'sha256': '95cc611e3b2457447ce62721a9b79d1a063d82058fc144d6d2a8dda53f30c3a6',
                      'bytes': 171,
                      'fields': 3,
                      'rows': 11},
            'warnings': [],
            'errors': [{'type': 'duplicate-label',
                        'title': 'Duplicate Label',
                        'description': 'Two columns in the header row have the '
                                       'same value. Column names should be '
                                       'unique.',
                        'message': 'Label "name" in the header at position "3" '
                                   'is duplicated to a label: at position "2"',
                        'tags': ['#table', '#header', '#label'],
                        'note': 'at position "2"',
                        'labels': ['id', 'name', 'name'],
                        'rowNumbers': [1],
                        'label': 'name',
                        'fieldName': 'name2',
                        'fieldNumber': 3}]}]}

As we can see, there are a lot of information; you can find its details description in "API Reference". Errors are grouped by tables; for some validation there are can be dozens of tables. Let's use the report.flatten function to simplify errors representation:

from pprint import pprint
from frictionless import validate

report = validate('capital-invalid.csv', pick_errors=['duplicate-label'])
pprint(report.flatten(['rowNumber', 'fieldNumber', 'code', 'message']))
[[None,
  3,
  None,
  'Label "name" in the header at position "3" is duplicated to a label: at '
  'position "2"']]

In some situation, an error can't be associated with a table; then it goes to the top-level report.errors property:

from frictionless import validate

report = validate('bad.json', type='schema')
print(report)
{'valid': False,
 'stats': {'tasks': 1, 'errors': 1, 'warnings': 0, 'seconds': 0.0},
 'warnings': [],
 'errors': [],
 'tasks': [{'name': 'bad',
            'type': 'json',
            'valid': False,
            'place': 'bad.json',
            'labels': [],
            'stats': {'errors': 1, 'warnings': 0, 'seconds': 0.0},
            'warnings': [],
            'errors': [{'type': 'schema-error',
                        'title': 'Schema Error',
                        'description': 'Provided schema is not valid.',
                        'message': 'Schema is not valid: cannot retrieve '
                                   'metadata "bad.json" because "[Errno 2] No '
                                   'such file or directory: \'bad.json\'"',
                        'tags': [],
                        'note': 'cannot retrieve metadata "bad.json" because '
                                '"[Errno 2] No such file or directory: '
                                '\'bad.json\'"'}]}]}

Validation Errors

The Error object is at the heart of the validation process. The Report has report.errors and report.tables[].errors properties that can contain the Error object. Let's explore it:

from frictionless import validate

report = validate('capital-invalid.csv', pick_errors=['duplicate-label'])
error = report.task.error # it's only available for 1 table / 1 error sitution
print(f'Type: "{error.type}"')
print(f'Title: "{error.title}"')
print(f'Tags: "{error.tags}"')
print(f'Note: "{error.note}"')
print(f'Message: "{error.message}"')
print(f'Description: "{error.description}"')
Type: "duplicate-label"
Title: "Duplicate Label"
Tags: "['#table', '#header', '#label']"
Note: "at position "2""
Message: "Label "name" in the header at position "3" is duplicated to a label: at position "2""
Description: "Two columns in the header row have the same value. Column names should be unique."

Above, we have listed universal error properties. Depending on the type of an error there can be additional ones. For example, for our duplicate-label error:

from frictionless import validate

report = validate('capital-invalid.csv', pick_errors=['duplicate-label'])
error = report.task.error # it's only available for 1 table / 1 error sitution
print(error)
{'type': 'duplicate-label',
 'title': 'Duplicate Label',
 'description': 'Two columns in the header row have the same value. Column '
                'names should be unique.',
 'message': 'Label "name" in the header at position "3" is duplicated to a '
            'label: at position "2"',
 'tags': ['#table', '#header', '#label'],
 'note': 'at position "2"',
 'labels': ['id', 'name', 'name'],
 'rowNumbers': [1],
 'label': 'name',
 'fieldName': 'name2',
 'fieldNumber': 3}

Please explore "Errors Reference" to learn about all the available errors and their properties.

Reference

Report (class)

ReportTask (class)

Report (class)

Report representation. A class that stores the summary of the validation action.

Signature

(*, name: Optional[str] = None, title: Optional[str] = None, description: Optional[str] = None, valid: bool, stats: types.IReportStats, warnings: List[str] = NOTHING, errors: List[Error] = NOTHING, tasks: List[ReportTask] = NOTHING) -> None

Parameters

  • name (Optional[str])
  • title (Optional[str])
  • description (Optional[str])
  • valid (bool)
  • stats (types.IReportStats)
  • warnings (List[str])
  • errors (List[Error])
  • tasks (List[ReportTask])

report.name (property)

A short url-usable (and preferably human-readable) name. This MUST be lower-case and contain only alphanumeric characters along with “_” or “-” characters.

Signature

Optional[str]

report.type (property)

Type of the package

Signature

ClassVar[Union[str, None]]

report.title (property)

A human-oriented title for the Report.

Signature

Optional[str]

report.description (property)

A brief description of the Detector.

Signature

Optional[str]

report.valid (property)

Flag to specify if the data is valid or not.

Signature

bool

report.stats (property)

Additional statistics of the data as defined in Stats class.

Signature

types.IReportStats

report.warnings (property)

List of warnings raised while validating the data.

Signature

List[str]

report.errors (property)

List of errors raised while validating the data.

Signature

List[Error]

report.tasks (property)

List of task that were applied during data validation.

Signature

List[ReportTask]

report.error (property)

Validation error (if there is only one)

report.task (property)

Validation task (if there is only one)

report.flatten (method)

Flatten the report Parameters spec (str[]): flatten specification

Signature

(spec: List[str] = [taskNumber, rowNumber, fieldNumber, type])

Parameters

  • spec (List[str])

Report.from_validation (method) (static)

Create a report from a validation

Signature

(*, time: float = 0, tasks: List[ReportTask] = [], errors: List[Error] = [], warnings: List[str] = [])

Parameters

  • time (float)
  • tasks (List[ReportTask])
  • errors (List[Error])
  • warnings (List[str])

Report.from_validation_reports (method) (static)

Create a report from a set of validation reports

Signature

(*, time: float, reports: List[Report])

Parameters

  • time (float)
  • reports (List[Report])

Report.from_validation_task (method) (static)

Create a report from a validation task

Signature

(resource: Resource, *, time: float, labels: List[str] = [], errors: List[Error] = [], warnings: List[str] = [])

Parameters

  • resource (Resource)
  • time (float)
  • labels (List[str])
  • errors (List[Error])
  • warnings (List[str])

report.to_summary (method)

Summary of the report

ReportTask (class)

Report task representation.

Signature

(*, name: str, type: Optional[str], title: Optional[str] = None, description: Optional[str] = None, valid: bool, place: str, labels: List[str], stats: types.IReportTaskStats, warnings: List[str] = NOTHING, errors: List[Error] = NOTHING) -> None

Parameters

  • name (str)
  • type (Optional[str])
  • title (Optional[str])
  • description (Optional[str])
  • valid (bool)
  • place (str)
  • labels (List[str])
  • stats (types.IReportTaskStats)
  • warnings (List[str])
  • errors (List[Error])

reportTask.name (property)

A short url-usable (and preferably human-readable) name. This MUST be lower-case and contain only alphanumeric characters along with “_” or “-” characters.

Signature

str

reportTask.type (property)

Sets the property tabular to True if the type is "table".

Signature

Optional[str]

reportTask.title (property)

A human-oriented title for the Report.

Signature

Optional[str]

reportTask.description (property)

A brief description of the Detector.

Signature

Optional[str]

reportTask.valid (property)

Flag to specify if the data is valid or not.

Signature

bool

reportTask.place (property)

Specifies the place of the file. For example: "", "data/table.csv" etc.

Signature

str

reportTask.labels (property)

List of labels of the task resource.

Signature

List[str]

reportTask.stats (property)

Additional statistics of the data as defined in Stats class.

Signature

types.IReportTaskStats

reportTask.warnings (property)

List of warnings raised while validating the data.

Signature

List[str]

reportTask.errors (property)

List of errors raised while validating the data.

Signature

List[Error]

reportTask.error (property)

Validation error if there is only one

reportTask.tabular (property)

Whether task's resource is tabular

Signature

bool

reportTask.flatten (method)

Flatten the report Parameters spec (any[]): flatten specification

Signature

(spec: List[str] = [rowNumber, fieldNumber, type])

Parameters

  • spec (List[str])

reportTask.to_summary (method)

Generate summary for validation task"

Signature

() -> str