Skip to content

Commit

Permalink
fix for #68
Browse files Browse the repository at this point in the history
  • Loading branch information
bryonjacob committed Oct 8, 2017
1 parent e25da76 commit d98067b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
18 changes: 18 additions & 0 deletions datadotworld/models/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,24 @@ def _iter_rows(self):
values.append(None)

table_row = schema_obj.cast_row(values)

# when the column is a string value, the jsontableschema
# library is incorrectly mapping the several literal
# string values ('null', 'none', '-', etc.) to the python
# `None` value - a deeper fix might be to reconsider using
# that library, or maybe fixing this issue in that
# library (since it's probably not a good idea to render
# a number of strings un-representable) - this fixes the
# problem for our result sets. Essentially, this zips
# over each result set and checks whether we mapped a
# non-null value to `None` in a string field, and if
# so it restores the non-null value before continuing
table_row = map(lambda field, original, mapped:
original if (not mapped) and original
and field.type == 'string'
else mapped,
schema_obj.fields, values, table_row)

yield OrderedDict(zip(field_names, table_row))
elif 'boolean' in self.raw_data:
# Results of an ASK query
Expand Down
10 changes: 10 additions & 0 deletions tests/datadotworld/models/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,15 @@ def test_dataframe(self, query_result_example, query_results):
equal_to((len(query_result_example['results']['bindings']),
len(metadata_names))))

def test_str_column(self, query_results):
'''
Test added for https://github.com/datadotworld/data.world-py/issues/68
added a value in the `st.name` column in sql_select.json of "NONE",
which was previously mapped to Python `None` - this verifies that we
have fixed that issue.
'''
for value in query_results.dataframe['st.name']:
assert_that(value)

def test_str(self, query_results, query_result_example):
assert_that(str(query_results), equal_to(str(query_result_example)))
2 changes: 1 addition & 1 deletion tests/fixtures/queries/sql_select.json
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@
},
"v_5": {
"type": "literal",
"value": "UT West Mall @ Guadalupe"
"value": "NONE"
},
"v_6": {
"type": "literal",
Expand Down

0 comments on commit d98067b

Please sign in to comment.