Fixed categorical filter not being converted to type, added tests

This commit is contained in:
Charlotte Weaver
2018-06-29 17:16:00 -07:00
parent 40f5b94075
commit 56c932a443
2 changed files with 82 additions and 9 deletions
+8 -9
View File
@@ -7,14 +7,16 @@ def _convert_variable(datatype, variable):
Convert variable to number (float/int)
Used for dataset metadata and for query string
:param datatype: type to convert to
:param variable: value of variable
:param variable (string or None): value of variable
:return: converted variable
:raises: ValueError
"""
try:
if variable and datatype == "int":
if variable is None:
return variable
if datatype == "int":
variable = int(variable)
elif variable and datatype == "float":
elif datatype == "float":
variable = float(variable)
return variable
except ValueError:
@@ -23,12 +25,9 @@ def _convert_variable(datatype, variable):
def parse_filter(filter, schema):
"""
{key: variable_type
value_type
query
:param filter:
:param schema:
:param filter: flask's request.args
:param schema: dictionary schema
:return:
"""
query = {}
@@ -41,7 +40,7 @@ def parse_filter(filter, schema):
"value_type": schema[key]["type"]
}
if query[key]["variable_type"] == "categorical":
query[key]["query"] = _convert_variable(query[key]["value_type"], value)
query[key]["query"] = [_convert_variable(query[key]["value_type"], v) for v in value]
elif query[key]["variable_type"] == "continuous":
value = value[0]
try: