Skip to content

Row validation/manipulation #20

Open
@robcowie

Description

@robcowie

Do you have any thoughts on the addition of row validation support, perhaps in the form of a per-Dataset array of callables that are applied to the row on append/insert? I'm unsure if the Dataset is the place for this kind of row data manipulation and validation.

I envisage passing an array of callables on Dataset initialisation which are then applied on row insert. Each callable returns the value to include in the row, or raises an exception. All errors are captured and the Dataset raises InvalidData. For example:

def oneof(val, row):
    valid = ['red', 'green', 'blue']
    if val in valid:
        return val
    raise InvalidData('Row column %d must be one of %s' % (row.index(val), valid))

data = tablib.Dataset(processors=[int, int, oneof])

data.append(('1', '45', 'green')) ## insert successfully
data.append(('1', '45', 'orange'))  ## InvalidData raised
data.append(('NaN', '45', 'orange'))  ## InvalidData raised

I don't want to start any work on this if you have already given it some thought and decided against it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions