jazzband / jazzband/tablib

Row validation/manipulation

Open
#20 1 comment 0 reactions 0 assignees View on GitHub
idea
Dominant language
Python
Stars
4.8k
Forks
617
PR merge metrics
No merged PRs in 30d

Description

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:

```python
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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.