Skip to content

Commit

Permalink
Bryon issue 68 (#69)
Browse files Browse the repository at this point in the history
* fix for #68

* updated version
  • Loading branch information
bryonjacob authored and rflprr committed Oct 10, 2017
1 parent e25da76 commit 2aad577
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion datadotworld/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from datadotworld.config import FileConfig, ChainedConfig
from datadotworld.datadotworld import DataDotWorld, UriParam

__version__ = '1.4.2'
__version__ = '1.4.3'

# Convenience top-level functions

Expand Down
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 2aad577

Please sign in to comment.