Skip to content

Commit

Permalink
Fix problem with partial schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
akariv committed May 20, 2016
1 parent 53ee8ce commit bc779d2
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions datapackage/resource.py
Expand Up @@ -8,6 +8,7 @@
import json
import six
import six.moves.urllib as urllib
from future.utils import raise_with_traceback
import tabulator
import jsontableschema

Expand Down Expand Up @@ -332,15 +333,17 @@ def __iter__(self):

def __next__(self):
row = next(self._tabulator_iter)
row_dict = {}
row = dict(zip(row.headers,row.values))
if self._schema is not None:
for index, field in enumerate(self._schema.fields):
value = row.values[index]
value = self._schema.cast(field['name'], value)
row_dict[field['name']] = value
else:
row_dict = dict(zip(row.headers, row.values))
return row_dict
for field in self._schema.fields:
field_name = field['name']
value = row[field_name]
try:
value = self._schema.cast(field_name, value)
except Exception as exception:
raise_with_traceback(ValueError('Cannot cast %r for <%s>' % (value, field_name)))
row[field_name] = value
return row

def next(self):
# For Py27 compatibility
Expand Down

0 comments on commit bc779d2

Please sign in to comment.