Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from goodtables import validate
- import json
- report = validate('./data.csv', schema='./schema.json', headers=1)
- print(json.dumps(report))
- """
- report
- {
- "time": 0.007,
- "valid": false,
- "error-count": 2,
- "table-count": 1,
- "tables": [
- {
- "time": 0.005,
- "valid": false,
- "error-count": 2,
- "row-count": 10,
- "source": "./data.csv",
- "headers": [
- "id",
- "age",
- "name"
- ],
- "scheme": "file",
- "format": "csv",
- "encoding": "utf-8",
- "schema": "table-schema",
- "errors": [
- {
- "code": "unique-constraint",
- "row-number": 4,
- "column-number": 1,
- "message": "Rows 2, 3, 4 has unique constraint violation in column 1",
- "message-data": {
- "row_numbers": "2, 3, 4"
- }
- },
- {
- "code": "unique-constraint",
- "row-number": 10,
- "column-number": 1,
- "message": "Rows 2, 3, 4, 5, 6, 7, 8, 9, 10 has unique constraint violation in column 1",
- "message-data": {
- "row_numbers": "2, 3, 4, 5, 6, 7, 8, 9, 10"
- }
- }
- ]
- }
- ],
- "warnings": [],
- "preset": "table"
- }
- """
- """
- data.csv
- id,age,name
- 1,1,Paul
- 2,23,Jimmy
- 1,33,Jane
- 4,24,Judy
- 1,1,meow
- 14,24,Judy
- 24,24,Judy
- 34,24,Judy
- 44,24,Judy
- """
- """
- schema.json
- {
- "fields": [{
- "name": "id",
- "type": "integer",
- "constraints": {
- "maximum": 100,
- "unique": true
- }
- }, {
- "name": "age",
- "type": "integer"
- }, {
- "name": "name",
- "type": "string",
- "constraints": {
- "required": true
- }
- }]
- }
- """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement