Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. from goodtables import validate
  2. import json
  3.  
  4.  
  5. report = validate('./data.csv', schema='./schema.json', headers=1)
  6.  
  7. print(json.dumps(report))
  8.  
  9. """
  10. report
  11.  
  12. {
  13. "time": 0.007,
  14. "valid": false,
  15. "error-count": 2,
  16. "table-count": 1,
  17. "tables": [
  18. {
  19. "time": 0.005,
  20. "valid": false,
  21. "error-count": 2,
  22. "row-count": 10,
  23. "source": "./data.csv",
  24. "headers": [
  25. "id",
  26. "age",
  27. "name"
  28. ],
  29. "scheme": "file",
  30. "format": "csv",
  31. "encoding": "utf-8",
  32. "schema": "table-schema",
  33. "errors": [
  34. {
  35. "code": "unique-constraint",
  36. "row-number": 4,
  37. "column-number": 1,
  38. "message": "Rows 2, 3, 4 has unique constraint violation in column 1",
  39. "message-data": {
  40. "row_numbers": "2, 3, 4"
  41. }
  42. },
  43. {
  44. "code": "unique-constraint",
  45. "row-number": 10,
  46. "column-number": 1,
  47. "message": "Rows 2, 3, 4, 5, 6, 7, 8, 9, 10 has unique constraint violation in column 1",
  48. "message-data": {
  49. "row_numbers": "2, 3, 4, 5, 6, 7, 8, 9, 10"
  50. }
  51. }
  52. ]
  53. }
  54. ],
  55. "warnings": [],
  56. "preset": "table"
  57. }
  58.  
  59.  
  60. """
  61.  
  62. """
  63. data.csv
  64. id,age,name
  65. 1,1,Paul
  66. 2,23,Jimmy
  67. 1,33,Jane
  68. 4,24,Judy
  69. 1,1,meow
  70. 14,24,Judy
  71. 24,24,Judy
  72. 34,24,Judy
  73. 44,24,Judy
  74. """
  75.  
  76. """
  77. schema.json
  78. {
  79. "fields": [{
  80. "name": "id",
  81. "type": "integer",
  82. "constraints": {
  83. "maximum": 100,
  84. "unique": true
  85. }
  86. }, {
  87. "name": "age",
  88. "type": "integer"
  89. }, {
  90. "name": "name",
  91. "type": "string",
  92. "constraints": {
  93. "required": true
  94. }
  95. }]
  96. }
  97. """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement