Skip to content

Commit 159e683

Browse files
authored
Merge pull request #2144 from keflavich/jplspec_small
Small changes to JPLspec
2 parents b7f2553 + 86d09b3 commit 159e683

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

CHANGES.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ Service fixes and enhancements
1414
Infrastructure, Utility and Other Changes and Additions
1515
-------------------------------------------------------
1616

17+
- JPLSpec now raises an EmptyResponseError if the returned result is empty.
18+
The API for JPLspec's ``lookup_table.find`` function returns a dictionary
19+
instead of values (for compatibility w/CDMS). [#2144]
1720

1821

1922
0.4.3 (2021-07-07)

astroquery/exceptions.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,10 @@ class MaxResultsWarning(AstropyWarning):
9696
results are returned.
9797
"""
9898
pass
99+
100+
101+
class EmptyResponseError(ValueError):
102+
"""
103+
Astroquery error class to be raised when the query returns an empty result
104+
"""
105+
pass

astroquery/jplspec/core.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# import configurable items declared in __init__.py
1010
from . import conf
1111
from . import lookup_table
12+
from astroquery.exceptions import EmptyResponseError, InvalidQueryError
1213

1314

1415
__all__ = ['JPLSpec', 'JPLSpecClass']
@@ -104,11 +105,11 @@ def query_lines_async(self, min_frequency, max_frequency,
104105
if molecule is not None:
105106
if parse_name_locally:
106107
self.lookup_ids = build_lookup()
107-
payload['Mol'] = tuple(self.lookup_ids.find(molecule, flags))
108+
payload['Mol'] = tuple(self.lookup_ids.find(molecule, flags).values())
108109
if len(molecule) == 0:
109-
raise ValueError('No matching species found. Please\
110-
refine your search or read the Docs\
111-
for pointers on how to search.')
110+
raise InvalidQueryError('No matching species found. Please '
111+
'refine your search or read the Docs '
112+
'for pointers on how to search.')
112113
else:
113114
payload['Mol'] = molecule
114115

@@ -156,6 +157,9 @@ def _parse_result(self, response, verbose=False):
156157
QN": Quantum numbers for the lower state.
157158
"""
158159

160+
if 'Zero lines were found' in response.text:
161+
raise EmptyResponseError(f"Response was empty; message was '{response.text}'.")
162+
159163
# data starts at 0 since regex was applied
160164
# Warning for a result with more than 1000 lines:
161165
# THIS form is currently limited to 1000 lines.

astroquery/jplspec/lookup_table.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ def find(self, s, flags):
3535
if match:
3636
out[k] = v
3737

38-
return out.values()
38+
return out

0 commit comments

Comments
 (0)