How to use the goodtables.cells.create_cells function in goodtables

To help you get started, we’ve selected a few goodtables examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github frictionlessdata / goodtables-py / tests / test_cells.py View on Github external
def test_create_cells_with_values(self):
        headers = [
            'name',
            'value',
        ]
        schema_fields = [
            'name_schema',
            'value_schema',
        ]
        values = [
            'Jane',
            51,
        ]

        cells = goodtables.cells.create_cells(headers, schema_fields, values)
        expected_cells = [
            goodtables.cells.create_cell('name', 'Jane', 'name_schema', 1),
            goodtables.cells.create_cell('value', 51, 'value_schema', 2),
        ]

        assert cells == [dict(cell) for cell in expected_cells]
github frictionlessdata / goodtables-py / tests / test_cells.py View on Github external
def test_create_header_cells(self):
        # Header cells are cells that have no value
        # (The value becomes the header's value)
        headers = [
            'name',
            'value',
        ]
        schema_fields = [
            'name_schema',
            'value_schema',
        ]

        cells = goodtables.cells.create_cells(headers, schema_fields)
        expected_cells = [
            goodtables.cells.create_cell('name', 'name', 'name_schema', 1),
            goodtables.cells.create_cell('value', 'value', 'value_schema', 2),
        ]

        assert cells == expected_cells
github frictionlessdata / goodtables-py / tests / test_cells.py View on Github external
def test_create_cells_with_incomplete_values(self):
        headers = [
            'name',
            'value',
        ]
        schema_fields = [
            'name_schema',
            'value_schema',
        ]
        values = [
            'Jane',
        ]

        cells = goodtables.cells.create_cells(headers, schema_fields, values)
        expected_cells = [
            goodtables.cells.create_cell('name', 'Jane', 'name_schema', 1),
            goodtables.cells.create_cell('value', None, 'value_schema', 2),
        ]

        assert cells == [dict(cell) for cell in expected_cells]
github frictionlessdata / goodtables-py / tests / test_cells.py View on Github external
def test_create_cells_with_none_values(self):
        # These happen when loading data from a ODS file with empty cells.
        headers = [
            'name',
            'value',
        ]
        schema_fields = [
            'name_schema',
            'value_schema',
        ]
        values = [
            None,
            51,
        ]

        cells = goodtables.cells.create_cells(headers, schema_fields, values)
        expected_cells = [
            goodtables.cells.create_cell('name', None, 'name_schema', 1),
            goodtables.cells.create_cell('value', 51, 'value_schema', 2),
        ]

        assert cells == [dict(cell) for cell in expected_cells]
github frictionlessdata / goodtables-py / goodtables / inspector.py View on Github external
prepare_func = getattr(check['func'], 'prepare', None)
            if not prepare_func:
                continue
            success = prepare_func(stream, schema, extra)
            if not success:
                checks.remove(check)
        if not checks:
            fatal_error = True

        # Head checks
        if not fatal_error:
            # Prepare cells
            fields = [None] * len(headers)
            if schema is not None:
                fields = schema.fields
            header_cells = cells.create_cells(headers, fields)

            # Fix for issue 312
            has_headers = headers is not None
            if has_headers:
                head_checks = _filter_checks(checks, context='head')
                for check in head_checks:
                    if not header_cells:
                        break
                    check_func = getattr(check['func'], 'check_headers', check['func'])
                    errors += (check_func(header_cells, sample) or [])
                for error in errors:
                    error.row = None

            # Grab fields from cells, as there might have been new ones
            # inferred by the "extra-header" check
            fields = [c.get('field') for c in header_cells]
github frictionlessdata / goodtables-py / goodtables / inspector.py View on Github external
# Body checks
        if not fatal_error:
            body_checks = _filter_checks(checks, context='body')
            with stream:
                extended_rows = stream.iter(extended=True)
                while True:
                    try:
                        row_number, _, row = next(extended_rows)
                    except StopIteration:
                        break
                    except Exception as exception:
                        error, fatal_error = _compose_error_from_exception(exception)
                        errors.append(error)
                        break
                    row_cells = cells.create_cells(headers, fields, row, row_number)
                    for check in body_checks:
                        if not row_cells:
                            break
                        check_func = getattr(check['func'], 'check_row', check['func'])
                        errors += (check_func(row_cells) or [])
                    for error in reversed(errors):
                        if error.row is not None:
                            break
                        error.row = row
                    if row_number >= self.__row_limit:
                        warnings.append(
                            'Table "%s" inspection has reached %s row(s) limit' %
                            (source, self.__row_limit))
                        break
                    if len(errors) >= self.__error_limit:
                        warnings.append(