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\'"'}]}]}
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.
Report representation. A class that stores the summary of the validation action.
(*, 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
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]
Type of the package
ClassVar[Union[str, None]]
A human-oriented title for the Report.
Optional[str]
A brief description of the Detector.
Optional[str]
Flag to specify if the data is valid or not.
bool
Additional statistics of the data as defined in Stats class.
types.IReportStats
List of warnings raised while validating the data.
List[str]
List of errors raised while validating the data.
List[Error]
List of task that were applied during data validation.
List[ReportTask]
Validation error (if there is only one)
Validation task (if there is only one)
Flatten the report Parameters spec (str[]): flatten specification
(spec: List[str] = [taskNumber, rowNumber, fieldNumber, type])
Create a report from a validation
(*, time: float = 0, tasks: List[ReportTask] = [], errors: List[Error] = [], warnings: List[str] = [])
Create a report from a set of validation reports
(*, time: float, reports: List[Report])
Create a report from a validation task
(resource: Resource, *, time: float, labels: List[str] = [], errors: List[Error] = [], warnings: List[str] = [])
Summary of the report
Report task representation.
(*, 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
A short url-usable (and preferably human-readable) name. This MUST be lower-case and contain only alphanumeric characters along with “_” or “-” characters.
str
Sets the property tabular to True if the type is "table".
Optional[str]
A human-oriented title for the Report.
Optional[str]
A brief description of the Detector.
Optional[str]
Flag to specify if the data is valid or not.
bool
Specifies the place of the file. For example: "
str
List of labels of the task resource.
List[str]
Additional statistics of the data as defined in Stats class.
types.IReportTaskStats
List of warnings raised while validating the data.
List[str]
List of errors raised while validating the data.
List[Error]
Validation error if there is only one
Whether task's resource is tabular
bool
Flatten the report Parameters spec (any[]): flatten specification
(spec: List[str] = [rowNumber, fieldNumber, type])
Generate summary for validation task"
() -> str