Skip to content

Commit cf5a896

Browse files
authored
Merge pull request #3127 from snbianco/panstarrs-bug
Panstarrs Bugfix
2 parents 47f0eb0 + 77014db commit cf5a896

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

astroquery/mast/services.py

+11-7
Original file line numberDiff line numberDiff line change
@@ -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

astroquery/mast/tests/data/README.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ To generate `~astroquery.mast.tests.data.mission_columns.json`, use the followin
1313
...
1414
>>> resp = utils._simple_request('https://mast.stsci.edu/search/util/api/v0.1/column_list', {'mission': 'hst'})
1515
>>> with open('mission_columns.json', 'w') as file:
16-
... json.dump(resp.json(), file, indent=4)
16+
... json.dump(resp.json(), file, indent=4) # doctest: +SKIP
1717

1818
To generate `~astroquery.mast.tests.data.panstarrs_columns.json`, use the following:
1919

@@ -24,4 +24,4 @@ To generate `~astroquery.mast.tests.data.panstarrs_columns.json`, use the follow
2424
...
2525
>>> resp = utils._simple_request('https://catalogs.mast.stsci.edu/api/v0.1/panstarrs/dr2/mean/metadata.json')
2626
>>> with open('panstarrs_columns.json', 'w') as file:
27-
... json.dump(resp.json(), file, indent=4)
27+
... json.dump(resp.json(), file, indent=4) # doctest: +SKIP

0 commit comments

Comments
 (0)