How to use the goodtables.error.Error 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_error.py View on Github external
def test_sort_with_undefined_rows(self):
        first_error = Error('first', cell={'column-number': 1})
        second_error = Error('second', cell={'column-number': 2})

        assert sorted([second_error, first_error]) == [first_error, second_error]
github frictionlessdata / goodtables-py / tests / test_error.py View on Github external
def test_sort_with_undefined_rows(self):
        first_error = Error('first', cell={'column-number': 1})
        second_error = Error('second', cell={'column-number': 2})

        assert sorted([second_error, first_error]) == [first_error, second_error]
github frictionlessdata / goodtables-py / goodtables / inspector.py View on Github external
def _compose_error_from_schema_error(error):
    message_substitutions = {
        'error_message': error,
    }
    return Error(
        'schema-error',
        message_substitutions=message_substitutions
    )
github frictionlessdata / goodtables-py / goodtables / checks / type_or_format_error.py View on Github external
valid = True
            cell['value'] = field.cast_value(value, constraints=False)
        except tableschema.exceptions.TableSchemaException:
            valid = False

        # Skip if valid
        if valid:
            continue

        # Add error
        message_substitutions = {
            'value': '"{}"'.format(value),
            'field_type': '"{}"'.format(field.type),
            'field_format': '"{}"'.format(field.format),
        }
        error = Error(
            'type-or-format-error',
            cell,
            message_substitutions=message_substitutions
        )
        errors.append(error)

        # Remove cell
        cells.remove(cell)

    return errors
github frictionlessdata / goodtables-py / goodtables / checks / blank_header.py View on Github external
def blank_header(cells, sample=None):
    errors = []

    for cell in cells:

        # Skip if cell have non blank header
        if cell.get('header', False):
            continue

        # Add error
        error = Error('blank-header', cell)
        errors.append(error)

    return errors
github frictionlessdata / goodtables-py / goodtables / contrib / checks / blacklisted_value.py View on Github external
row_number=cells[0]['row-number'],
                message=message
            )
            return [error]

        # Check value
        value = cell.get('value')
        if value in self.__blacklist:
            message = (
                'Value "{value}" in column {column_number} on row {row_number}'
                ' is blacklisted'
            )
            message_substitutions = {
                'value': value,
            }
            error = Error(
                'blacklisted-value',
                cell,
                message=message,
                message_substitutions=message_substitutions
            )
            return [error]
github frictionlessdata / goodtables-py / goodtables / contrib / checks / sequential_value.py View on Github external
def check_row(self, cells):

        # Get cell
        cell = None
        for item in cells:
            if self.__column in [item['column-number'], item['header']]:
                cell = item
                break

        # Check cell
        if not cell:
            message = 'Sequential value check requires column "{column}" to exist'
            message = message.format(column=self.__column)
            error = Error(
                self.__code,
                row_number=cells[0]['row-number'],
                message=message
            )
            return [error]

        # Get value
        try:
            value = int(cell.get('value'))
        except (TypeError, ValueError):
            message = (
                'Sequential value check requires column "{column_number}"'
                ' to be an integer'
            )
            error = self._create_error(cell, message)
            return [error]
github frictionlessdata / goodtables-py / goodtables / contrib / checks / truncated_value.py View on Github external
# Check integer cutoff
            try:
                value = int(value)
                if value in _TRUNCATED_INTEGER_VALUES:
                    truncated = True
            except Exception:
                pass

            # Add error
            if truncated:
                message = (
                    'Value in column {column_number} for row {row_number}'
                    ' is probably truncated'
                )
                error = Error(
                    'truncated-value',
                    cell,
                    message=message
                )
                return [error]
github frictionlessdata / goodtables-py / goodtables / contrib / checks / sequential_value.py View on Github external
def _create_error(self, cell, message, message_substitutions=None):
        return Error(
            self.__code,
            cell,
            message=message,
            message_substitutions=message_substitutions
        )
github frictionlessdata / goodtables-py / goodtables / checks / missing_header.py View on Github external
def missing_header(cells, sample):
    errors = []

    for cell in copy(cells):

        # Skip if header in cell
        if cell.get('header') is not None:
            continue

        # Add error
        message_substitutions = {
            'field_name': '"{}"'.format(cell['field'].name),
        }
        error = Error(
            'missing-header',
            cell,
            message_substitutions=message_substitutions
        )
        errors.append(error)

        # Remove cell
        cells.remove(cell)

    return errors