@@ -52,14 +52,18 @@ def _json_to_table(json_obj, data_key='data'):
52
52
# for each item in info, type has to be converted from DB data types (SQL server in most cases)
53
53
# from missions_mast search service such as varchar, integer, float, boolean etc
54
54
# 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
57
61
58
62
# making type adjustments
59
63
if (col_type == "char" or col_type == "string" or 'varchar' in col_type or col_type == "null"
60
64
or col_type == 'datetime' ):
61
65
col_type = "str"
62
- ignore_value = "" if ( ignore_value is None ) else ignore_value
66
+ ignore_value = ""
63
67
elif col_type == "boolean" or col_type == "binary" :
64
68
col_type = "bool"
65
69
elif col_type == "unsignedbyte" :
@@ -68,19 +72,19 @@ def _json_to_table(json_obj, data_key='data'):
68
72
or col_type == 'integer' ):
69
73
# int arrays do not admit Non/nan vals
70
74
col_type = np .int64
71
- ignore_value = - 999 if ( ignore_value is None ) else ignore_value
75
+ ignore_value = - 999
72
76
elif col_type == "double" or col_type .lower () == "float" or col_type == "decimal" :
73
77
# int arrays do not admit Non/nan vals
74
78
col_type = np .float64
75
- ignore_value = - 999 if ( ignore_value is None ) else ignore_value
79
+ ignore_value = - 999
76
80
77
81
# Make the column list (don't assign final type yet or there will be errors)
78
82
try :
79
83
# Step through data array of values
80
84
col_data = np .array ([x [idx ] for x in json_obj [data_key ]], dtype = object )
81
85
except KeyError :
82
86
# 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 )
84
88
if ignore_value is not None :
85
89
col_data [np .where (np .equal (col_data , None ))] = ignore_value
86
90
@@ -92,7 +96,7 @@ def _json_to_table(json_obj, data_key='data'):
92
96
col_mask = np .equal (col_data , ignore_value )
93
97
94
98
# 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 ))
96
100
97
101
return data_table
98
102
0 commit comments