@@ -52,14 +52,18 @@ def _json_to_table(json_obj, data_key='data'):
5252 # for each item in info, type has to be converted from DB data types (SQL server in most cases)
5353 # from missions_mast search service such as varchar, integer, float, boolean etc
5454 # to corresponding numpy type
55- for idx , col , col_type , ignore_value in \
56- [(idx , x ['name' ], x [type_key ].lower (), None ) for idx , x in enumerate (json_obj ['info' ])]:
55+ for idx , col in enumerate (json_obj ['info' ]):
56+
57+ # get column name and type
58+ col_name = col .get ('column_name' ) or col .get ('name' )
59+ col_type = col [type_key ].lower ()
60+ ignore_value = None
5761
5862 # making type adjustments
5963 if (col_type == "char" or col_type == "string" or 'varchar' in col_type or col_type == "null"
6064 or col_type == 'datetime' ):
6165 col_type = "str"
62- ignore_value = "" if ( ignore_value is None ) else ignore_value
66+ ignore_value = ""
6367 elif col_type == "boolean" or col_type == "binary" :
6468 col_type = "bool"
6569 elif col_type == "unsignedbyte" :
@@ -68,19 +72,19 @@ def _json_to_table(json_obj, data_key='data'):
6872 or col_type == 'integer' ):
6973 # int arrays do not admit Non/nan vals
7074 col_type = np .int64
71- ignore_value = - 999 if ( ignore_value is None ) else ignore_value
75+ ignore_value = - 999
7276 elif col_type == "double" or col_type .lower () == "float" or col_type == "decimal" :
7377 # int arrays do not admit Non/nan vals
7478 col_type = np .float64
75- ignore_value = - 999 if ( ignore_value is None ) else ignore_value
79+ ignore_value = - 999
7680
7781 # Make the column list (don't assign final type yet or there will be errors)
7882 try :
7983 # Step through data array of values
8084 col_data = np .array ([x [idx ] for x in json_obj [data_key ]], dtype = object )
8185 except KeyError :
8286 # it's not a data array, fall back to using column name as it is array of dictionaries
83- col_data = np .array ([x [col ] for x in json_obj [data_key ]], dtype = object )
87+ col_data = np .array ([x [col_name ] for x in json_obj [data_key ]], dtype = object )
8488 if ignore_value is not None :
8589 col_data [np .where (np .equal (col_data , None ))] = ignore_value
8690
@@ -92,7 +96,7 @@ def _json_to_table(json_obj, data_key='data'):
9296 col_mask = np .equal (col_data , ignore_value )
9397
9498 # add the column
95- data_table .add_column (MaskedColumn (col_data .astype (col_type ), name = col , mask = col_mask ))
99+ data_table .add_column (MaskedColumn (col_data .astype (col_type ), name = col_name , mask = col_mask ))
96100
97101 return data_table
98102
0 commit comments