Skip to content

Commit 1446f1a

Browse files
authored
Merge pull request #2637 from keflavich/simbad_wrong_test_coordinates
Bugfix: SIMBAD test cleanup, ROW_LIMIT support
2 parents 74259c8 + 4cdf297 commit 1446f1a

File tree

4 files changed

+38
-27
lines changed

4 files changed

+38
-27
lines changed

CHANGES.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ simbad
158158
radius as a string in ``query_region()`` and ``query_region_async()``.
159159
[#2494]
160160
- Optional keyword arguments are now keyword only. [#2609]
161+
- ``ROW_LIMIT`` is now respected when running region queries; previously, it
162+
was ignored for region queries but respected for all others. A new warning,
163+
``BlankResponseWarning``, is introduced for use when one or more query terms result
164+
in a blank or missing row; previously, only a generic warning was issued.
165+
[#2637]
161166

162167
skyview
163168
^^^^^^^

astroquery/exceptions.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
__all__ = ['TimeoutError', 'InvalidQueryError', 'RemoteServiceError',
99
'TableParseError', 'LoginError', 'ResolverError',
1010
'NoResultsWarning', 'LargeQueryWarning', 'InputWarning',
11-
'AuthenticationWarning', 'MaxResultsWarning', 'CorruptDataWarning']
11+
'AuthenticationWarning', 'MaxResultsWarning', 'CorruptDataWarning',
12+
'BlankResponseWarning']
1213

1314

1415
class TimeoutError(Exception):
@@ -111,3 +112,10 @@ class EmptyResponseError(ValueError):
111112
Astroquery error class to be raised when the query returns an empty result
112113
"""
113114
pass
115+
116+
117+
class BlankResponseWarning(AstropyWarning):
118+
"""
119+
Astroquery warning to be raised if one or more rows in a table are bad, but
120+
not all rows are.
121+
"""

astroquery/simbad/core.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
from astroquery.query import BaseQuery
2121
from astroquery.utils import commons, async_to_sync
22-
from astroquery.exceptions import TableParseError, LargeQueryWarning
22+
from astroquery.exceptions import TableParseError, LargeQueryWarning, BlankResponseWarning
2323
from . import conf
2424

2525

@@ -135,7 +135,9 @@ def __warn(self):
135135
warnings.warn("Warning: The script line number %i raised "
136136
"an error (recorded in the `errors` attribute "
137137
"of the result table): %s" %
138-
(error.line, error.msg))
138+
(error.line, error.msg),
139+
BlankResponseWarning
140+
)
139141

140142
def __get_section(self, section_name):
141143
if section_name in self.__indexes:
@@ -938,7 +940,8 @@ def _get_query_header(self, get_raw=False):
938940
# if get_raw is set then don't fetch as votable
939941
if get_raw:
940942
return ""
941-
return "votable {" + ','.join(self.get_votable_fields()) + "}\nvotable open"
943+
row_limit = f"set limit {self.ROW_LIMIT}\n" if self.ROW_LIMIT > 0 else ""
944+
return f"{row_limit}votable {{{','.join(self.get_votable_fields())}}}\nvotable open"
942945

943946
def _get_query_footer(self, get_raw=False):
944947
return "" if get_raw else "votable close"
@@ -960,8 +963,6 @@ def _args_to_payload(self, *args, **kwargs):
960963
votable_header = self._get_query_header(get_raw)
961964
votable_footer = self._get_query_footer(get_raw)
962965

963-
if self.ROW_LIMIT > 0:
964-
script = "set limit " + str(self.ROW_LIMIT)
965966
script = "\n".join([script, votable_header, command])
966967
using_wildcard = False
967968
if kwargs.get('wildcard'):

astroquery/simbad/tests/test_simbad_remote.py

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
from astroquery.simbad import Simbad
1111
# Maybe we need to expose SimbadVOTableResult to be in the public API?
1212
from astroquery.simbad.core import SimbadVOTableResult
13+
from astroquery.exceptions import BlankResponseWarning
1314

1415

1516
# M42 coordinates
16-
ICRS_COORDS_M42 = SkyCoord("05h35m17.3s -05h23m28s", frame='icrs')
17+
ICRS_COORDS_M42 = SkyCoord("05h35m17.3s -05d23m28s", frame='icrs')
1718
ICRS_COORDS_SgrB2 = SkyCoord(266.835*u.deg, -28.38528*u.deg, frame='icrs')
1819
multicoords = SkyCoord([ICRS_COORDS_M42, ICRS_COORDS_SgrB2])
1920

@@ -99,8 +100,7 @@ def test_query_catalog(self, temp_dir):
99100

100101
def test_query_region_async(self, temp_dir):
101102
simbad = Simbad()
102-
# TODO: rewise once ROW_LIMIT is working
103-
simbad.TIMEOUT = 100
103+
simbad.ROW_LIMIT = 100
104104
simbad.cache_location = temp_dir
105105
response = simbad.query_region_async(
106106
ICRS_COORDS_M42, radius=2 * u.deg, equinox=2000.0, epoch='J2000')
@@ -112,12 +112,12 @@ def test_query_region_async_vector(self, temp_dir, radius):
112112
simbad = Simbad()
113113
simbad.cache_location = temp_dir
114114
response1 = simbad.query_region_async(multicoords, radius=radius)
115-
assert response1.request.body == 'script=votable+%7Bmain_id%2Ccoordinates%7D%0Avotable+open%0Aquery+coo+5%3A35%3A17.3+-80%3A52%3A00+radius%3D0.5s+frame%3DICRS+equi%3D2000.0%0Aquery+coo+17%3A47%3A20.4+-28%3A23%3A07.008+radius%3D0.5s+frame%3DICRS+equi%3D2000.0%0Avotable+close' # noqa
115+
assert response1.request.body == 'script=votable+%7Bmain_id%2Ccoordinates%7D%0Avotable+open%0Aquery+coo+5%3A35%3A17.3+-5%3A23%3A28+radius%3D0.5s+frame%3DICRS+equi%3D2000.0%0Aquery+coo+17%3A47%3A20.4+-28%3A23%3A07.008+radius%3D0.5s+frame%3DICRS+equi%3D2000.0%0Avotable+close' # noqa
116116

117117
def test_query_region(self, temp_dir):
118118
simbad = Simbad()
119-
# TODO: rewise once ROW_LIMIT is working
120119
simbad.TIMEOUT = 100
120+
simbad.ROW_LIMIT = 100
121121
simbad.cache_location = temp_dir
122122
result = simbad.query_region(ICRS_COORDS_M42, radius=2 * u.deg,
123123
equinox=2000.0, epoch='J2000')
@@ -149,7 +149,8 @@ def test_query_multi_object(self, temp_dir):
149149
assert len(result) == 2
150150
assert len(result.errors) == 0
151151

152-
result = simbad.query_objects(['M32', 'M81', 'gHer'])
152+
with pytest.warns(BlankResponseWarning):
153+
result = simbad.query_objects(['M32', 'M81', 'gHer'])
153154
# 'gHer' is not a valid Simbad identifier - it should be 'g Her' to
154155
# get the star
155156
assert len(result) == 2
@@ -182,29 +183,25 @@ def test_query_object_ids(self, temp_dir):
182183
def test_null_response(self, temp_dir, function):
183184
simbad = Simbad()
184185
simbad.cache_location = temp_dir
185-
assert (simbad.__getattribute__(function)('idonotexist')
186-
is None)
186+
with pytest.warns(BlankResponseWarning):
187+
assert (simbad.__getattribute__(function)('idonotexist')
188+
is None)
187189

188190
# Special case of null test: list of nonexistent parameters
189191
def test_query_objects_null(self, temp_dir):
190192
simbad = Simbad()
191193
simbad.cache_location = temp_dir
192-
assert simbad.query_objects(['idonotexist', 'idonotexisteither']) is None
194+
with pytest.warns(BlankResponseWarning):
195+
assert simbad.query_objects(['idonotexist', 'idonotexisteither']) is None
193196

194-
# Special case of null test: zero-sized region
195-
def test_query_region_null(self, temp_dir):
197+
# Special case of null test: zero-size and very small region
198+
@pytest.mark.parametrize('radius', ["0d", 1.0*u.marcsec])
199+
def test_query_region_null(self, temp_dir, radius):
196200
simbad = Simbad()
197201
simbad.cache_location = temp_dir
198-
result = simbad.query_region(SkyCoord("00h01m0.0s 00h00m0.0s"), radius="0d",
199-
equinox=2000.0, epoch='J2000')
200-
assert result is None
201-
202-
# Special case of null test: very small region
203-
def test_query_small_region_null(self, temp_dir):
204-
simbad = Simbad()
205-
simbad.cache_location = temp_dir
206-
result = simbad.query_region(SkyCoord("00h01m0.0s 00h00m0.0s"), radius=1.0 * u.marcsec,
207-
equinox=2000.0, epoch='J2000')
202+
with pytest.warns(BlankResponseWarning):
203+
result = simbad.query_region(SkyCoord("00h01m0.0s 00h00m0.0s"), radius=1.0 * u.marcsec,
204+
equinox=2000.0, epoch='J2000')
208205
assert result is None
209206

210207
# Special case : zero-sized region with one object

0 commit comments

Comments
 (0)