data.world-py
data.world-py copied to clipboard
String literal 'NONE' gets mapped to Python None value in result sets
In a SQL or SPARQL response, the literal string value 'NONE' (case-insensitive) is converted into the python value None:
>>> datadotworld.query('bryon/odin-2015-2016', 'SELECT ?value WHERE{ BIND("NONE" AS ?value)}', query_type='sparql').table
[OrderedDict([('value', None)])]
>>> datadotworld.query('bryon/odin-2015-2016', 'SELECT ?value WHERE{ BIND("ABCD" AS ?value)}', query_type='sparql').table
[OrderedDict([('value', 'ABCD')])]
>>> datadotworld.query('bryon/odin-2015-2016', 'SELECT "NONE" AS value').table
[OrderedDict([('value', None)])]
>>> datadotworld.query('bryon/odin-2015-2016', 'SELECT "ABCD" AS value').table
[OrderedDict([('value', 'ABCD')])]
UGH. so, this is because we are depending on the datapackage library which is hardcoded to treat any of these strings:
['null', 'none', 'nil', 'nan', '-']
as None when they occur as a value in a StringValue-typed column. In the context of returning query results from our servers, this is always wrong - we have the capacity to handle null results just fine explicitly.
Some work here is still necessary after Bryon's hotfix to ensure that there is no broader impact and, possibly, a simpler and more generalized solution.