Skip to content

Commit 975ae1a

Browse files
syed-gilanibsipocz
authored andcommitted
made all data type comparisons in lower case and added comments about type conversion
1 parent 4ad97b8 commit 975ae1a

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

astroquery/mast/services.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,32 +49,29 @@ def _json_to_table(json_obj, data_key='data'):
4949
type_key = 'type' if json_obj['info'][0].get('type') else 'db_type'
5050

5151
# for each item in info, store the type and column name
52+
# for each item in info, type has to be converted from DB data types (SQL server in most cases)
53+
# to corresponding numpy type
5254
for idx, col, col_type, ignore_value in \
53-
[(idx, x['name'], x[type_key], "NULL") for idx, x in enumerate(json_obj['info'])]:
55+
[(idx, x['name'], x[type_key].lower(), None) for idx, x in enumerate(json_obj['info'])]:
5456

55-
# if default value is NULL, set ignore value to None
56-
if ignore_value == "NULL":
57-
ignore_value = None
5857
# making type adjustments
59-
if col_type == "char" or col_type == "STRING" or 'VARCHAR' in col_type or col_type == "NULL":
58+
if (col_type == "char" or col_type == "string" or 'varchar' in col_type or col_type == "null" or
59+
col_type == 'datetime'):
6060
col_type = "str"
6161
ignore_value = "" if (ignore_value is None) else ignore_value
62-
elif col_type == "boolean" or col_type == "BINARY":
62+
elif col_type == "boolean" or col_type == "binary":
6363
col_type = "bool"
6464
elif col_type == "unsignedByte":
6565
col_type = np.ubyte
66-
elif (col_type == "int" or col_type == "short" or col_type == "long" or col_type == "NUMBER"
67-
or col_type == 'INTEGER'):
66+
elif (col_type == "int" or col_type == "short" or col_type == "long" or col_type == "number"
67+
or col_type == 'integer'):
6868
# int arrays do not admit Non/nan vals
6969
col_type = np.int64
7070
ignore_value = -999 if (ignore_value is None) else ignore_value
71-
elif col_type == "double" or col_type.lower() == "float" or col_type == "DECIMAL":
71+
elif col_type == "double" or col_type.lower() == "float" or col_type == "decimal":
7272
# int arrays do not admit Non/nan vals
7373
col_type = np.float64
7474
ignore_value = -999 if (ignore_value is None) else ignore_value
75-
elif col_type == "DATETIME":
76-
col_type = "str"
77-
ignore_value = "" if (ignore_value is None) else ignore_value
7875

7976
# Make the column list (don't assign final type yet or there will be errors)
8077
try:

0 commit comments

Comments
 (0)