Skip to content

Commit 3e3fc89

Browse files
committed
this time really fix the problem & add a regression test
1 parent 535da2d commit 3e3fc89

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

astroquery/splatalogue/core.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import warnings
99
from astropy.io import ascii
1010
from astropy import units as u
11+
from astropy import log
1112
from ..query import BaseQuery
1213
from ..utils import async_to_sync
1314
from ..utils.docstr_chompers import prepend_docstr_noreturns
@@ -294,9 +295,11 @@ def _parse_kwargs(self, min_frequency=None, max_frequency=None,
294295
"are {vers}".format(vers=str(self.versions)))
295296

296297
if exclude == 'none':
298+
log.debug("Exclude is 'none'")
297299
for e in ('potential', 'atmospheric', 'probable', 'known'):
298-
if 'no_'+e in payload:
299-
del payload['no_' + e]
300+
# Setting a keyword value to 'None' removes it (see query_lines_async)
301+
log.debug("Setting no_{0} to None".format(e))
302+
payload['no_' + e] = None
300303
elif exclude is not None:
301304
for e in exclude:
302305
payload['no_' + e] = 'no_' + e
@@ -389,6 +392,9 @@ def query_lines_async(self, min_frequency=None, max_frequency=None,
389392
max_frequency=max_frequency,
390393
**kwargs))
391394

395+
# Add an extra step: sometimes, need to REMOVE keywords
396+
data_payload = {k:v for k,v in data_payload.items() if v is not None}
397+
392398
if get_query_payload:
393399
return data_payload
394400

astroquery/splatalogue/tests/test_splatalogue.py

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from ...utils.testing_tools import MockResponse
44
from astropy import units as u
55
from astropy.tests.helper import pytest, remote_data
6+
from astropy.extern.six.moves import urllib_parse
67
import requests
78
import os
89

@@ -112,7 +113,33 @@ def test_band_crashorno():
112113
@remote_data
113114
def test_version_selection():
114115
results = splatalogue.Splatalogue.query_lines(
115-
min_frequency=703 * u.GHz, max_frequency=706 * u.GHz,
116-
chemical_name='Acetaldehyde', version='v1.0')
117-
118-
assert len(results) == 133
116+
min_frequency= 703*u.GHz,
117+
max_frequency=706*u.GHz,
118+
chemical_name='Acetaldehyde',
119+
version='v1.0'
120+
)
121+
assert len(results)==1
122+
123+
def test_exclude(patch_post):
124+
# regression test for issue 616
125+
d = splatalogue.Splatalogue.query_lines_async(114 * u.GHz, 116 * u.GHz,
126+
chemical_name=' CO ',
127+
get_query_payload=True)
128+
129+
exclusions = {'no_atmospheric': 'no_atmospheric',
130+
'no_potential': 'no_potential',
131+
'no_probable': 'no_probable',}
132+
133+
for k,v in exclusions.items():
134+
assert d[k] == v
135+
136+
d = splatalogue.Splatalogue.query_lines_async(114 * u.GHz, 116 * u.GHz,
137+
chemical_name=' CO ',
138+
exclude='none',
139+
get_query_payload=True)
140+
141+
for k,v in exclusions.items():
142+
assert k not in d
143+
144+
for k in d:
145+
assert k[:3] != 'no_'

0 commit comments

Comments
 (0)