Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Row validation/manipulation #20

Open
robcowie opened this issue Jun 19, 2011 · 1 comment
Open

Row validation/manipulation #20

robcowie opened this issue Jun 19, 2011 · 1 comment
Labels

Comments

@robcowie
Copy link

robcowie commented Jun 19, 2011

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.

@kennethreitz
Copy link
Contributor

kennethreitz commented Jun 21, 2011

Thanks for the thoughts!

I've thought about this before, and the options boiled down to:

  1. Adding Column Types (int, str, regex test)
  2. Adding a Hook System

The plan for the time being is to implement the second option. A hook will be a callable that you'll register to be called when a certain event takes place.

def verify_dataset(dset):
    ...

data.when_changed = verify_dataset

@hugovk hugovk added the idea label Oct 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants