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

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

(*, name: Optional[str] = None, 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
  • name (Optional[str])
  • 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)

Specify the number of rows to compare with actual rows in the table. If the actual number of rows are less than num_rows it will notify user as errors.

Signature

Optional[int]

checks.table_dimensions.min_rows (property)

Specify the minimum number of rows that should be in the table. If the actual number of rows are less than min_rows it will notify user as errors.

Signature

Optional[int]

checks.table_dimensions.max_rows (property)

Specify the maximum number of rows allowed. If the actual number of rows are more than max_rows it will notify user as errors.

Signature

Optional[int]

checks.table_dimensions.num_fields (property)

Specify the number of fields to compare with actual fields in the table. If the actual number of fields are less than num_fields it will notify user as errors.

Signature

Optional[int]

checks.table_dimensions.min_fields (property)

Specify the minimum number of fields that should be in the table. If the actual number of fields are less than min_fields it will notify user as errors.

Signature

Optional[int]

checks.table_dimensions.max_fields (property)

Specify the maximum number of expected fields. If the actual number of fields are more than max_fields it will notify user as errors.

Signature

Optional[int]