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

Table Checks

Table Dimensions

This check is used to validate if your data has expected dimensions as: exact number of rows , minimum and maximum number of rows, exact number of fields , minimum and maximum number of fields.

Basic Example

from pprint import pprint
from frictionless import validate, checks

source = [
    ["row", "salary", "bonus"],
    [2, 1000, 200],
    [3, 2500, 500],
    [4, 1300, 500],
    [5, 5000, 1000],
]
report = validate(source, checks=[checks.table_dimensions(num_rows=5)])
pprint(report.flatten(["type", "message"]))
[['table-dimensions',
  'The data source does not have the required dimensions: number of rows is 4, '
  'the required is 5']]

Multiple Limits

You can also give multiples limits at the same time:

from pprint import pprint
from frictionless import validate, checks

source = [
    ["row", "salary", "bonus"],
    [2, 1000, 200],
    [3, 2500, 500],
    [4, 1300, 500],
    [5, 5000, 1000],
]
report = validate(source, checks=[checks.table_dimensions(num_rows=5, num_fields=4)])
pprint(report.flatten(["type", "message"]))
[['table-dimensions',
  'The data source does not have the required dimensions: number of fields is '
  '3, the required is 4'],
 ['table-dimensions',
  'The data source does not have the required dimensions: number of rows is 4, '
  'the required is 5']]

Using Declaratively

It is possible to use de check declaratively as:

from pprint import pprint
from frictionless import Check, validate, checks

source = [
    ["row", "salary", "bonus"],
    [2, 1000, 200],
    [3, 2500, 500],
    [4, 1300, 500],
    [5, 5000, 1000],
]

check = Check.from_descriptor({"type": "table-dimensions", "minFields": 4, "maxRows": 3})
report = validate(source, checks=[check])
pprint(report.flatten(["type", "message"]))
[['table-dimensions',
  'The data source does not have the required dimensions: number of fields is '
  '3, the minimum is 4'],
 ['table-dimensions',
  'The data source does not have the required dimensions: number of rows is 4, '
  'the maximum is 3']]

But the table dimensions check arguments num_rows, min_rows, max_rows, num_fields, min_fields, max_fields must be passed in camelCase format as the example above i.e. numRows, minRows, maxRows, numFields, minFields and maxFields.

Reference

checks.table_dimensions (class)

checks.table_dimensions (class)

Check for minimum and maximum table dimensions

Signature

(*, title: Optional[str] = None, description: Optional[str] = None, num_rows: Optional[int] = None, min_rows: Optional[int] = None, max_rows: Optional[int] = None, num_fields: Optional[int] = None, min_fields: Optional[int] = None, max_fields: Optional[int] = None) -> None

Parameters
  • title (Optional[str])
  • description (Optional[str])
  • num_rows (Optional[int])
  • min_rows (Optional[int])
  • max_rows (Optional[int])
  • num_fields (Optional[int])
  • min_fields (Optional[int])
  • max_fields (Optional[int])

checks.table_dimensions.num_rows (property)

NOTE: add docs

Signature

Optional[int]

checks.table_dimensions.min_rows (property)

NOTE: add docs

Signature

Optional[int]

checks.table_dimensions.max_rows (property)

NOTE: add docs

Signature

Optional[int]

checks.table_dimensions.num_fields (property)

NOTE: add docs

Signature

Optional[int]

checks.table_dimensions.min_fields (property)

NOTE: add docs

Signature

Optional[int]

checks.table_dimensions.max_fields (property)

NOTE: add docs

Signature

Optional[int]

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.