Skip to content

Commit 31ca364

Browse files
committed
feat: add a warning on empty response
1 parent 9f65c6f commit 31ca364

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

astroquery/simbad/core.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
from astroquery.query import BaseVOQuery
2020
from astroquery.utils import commons
21-
from astroquery.exceptions import LargeQueryWarning
21+
from astroquery.exceptions import LargeQueryWarning, NoResultsWarning
2222
from astroquery.simbad.utils import (_catch_deprecated_fields_with_arguments,
2323
_wildcard_to_regexp, CriteriaTranslator,
2424
query_criteria_fields)
@@ -1397,7 +1397,7 @@ def _query(self, top, columns, joins, criteria, from_table="basic",
13971397
`~astropy.table.Table`
13981398
The result of the query to SIMBAD.
13991399
"""
1400-
top = f" TOP {top}" if top != -1 else ""
1400+
top_part = f" TOP {top}" if top != -1 else ""
14011401

14021402
# columns
14031403
input_columns = [f'{column.table}."{column.name}" AS "{column.alias}"' if column.alias is not None
@@ -1425,9 +1425,16 @@ def _query(self, top, columns, joins, criteria, from_table="basic",
14251425
else:
14261426
criteria = ""
14271427

1428-
query = f"SELECT{top}{columns} FROM {from_table}{join}{criteria}"
1428+
query = f"SELECT{top_part}{columns} FROM {from_table}{join}{criteria}"
14291429

1430-
return self.query_tap(query, get_query_payload=get_query_payload, **uploads)
1430+
response = self.query_tap(query, get_query_payload=get_query_payload,
1431+
maxrec=self.hardlimit,
1432+
**uploads)
1433+
1434+
if len(response) == 0 and top != 0:
1435+
warnings.warn("The request executed correctly, but there was no data corresponding"
1436+
" to these criteria in SIMBAD", NoResultsWarning)
1437+
return response
14311438

14321439

14331440
Simbad = SimbadClass()

astroquery/simbad/tests/test_simbad.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
from ... import simbad
1515
from .test_simbad_remote import multicoords
16-
from astroquery.exceptions import LargeQueryWarning
16+
from astroquery.exceptions import LargeQueryWarning, NoResultsWarning
1717

1818

1919
GALACTIC_COORDS = SkyCoord(l=-67.02084 * u.deg, b=-29.75447 * u.deg, frame="galactic")
@@ -486,6 +486,16 @@ def test_query_tap_cache_call(monkeypatch):
486486
assert simbad.Simbad.query_tap("select top 1 * from basic") == msg
487487

488488

489+
@pytest.mark.usefixtures("_mock_simbad_class")
490+
def test_empty_response_warns(monkeypatch):
491+
# return something of length zero
492+
monkeypatch.setattr(simbad.core.Simbad, "query_tap", lambda _, get_query_payload, maxrec: [])
493+
msg = ("The request executed correctly, but there was no data corresponding to these"
494+
" criteria in SIMBAD")
495+
with pytest.warns(NoResultsWarning, match=msg):
496+
simbad.core.Simbad.query_catalog("unknown_catalog")
497+
498+
489499
# ---------------------------------------------------
490500
# Test the adql string for query_tap helper functions
491501
# ---------------------------------------------------

astroquery/simbad/tests/test_simbad_remote.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from astropy.utils.exceptions import AstropyDeprecationWarning
77
from astropy.table import Table
88

9+
from astroquery.exceptions import NoResultsWarning
910
from astroquery.simbad import Simbad
1011
from astroquery.simbad.core import _cached_query_tap, _Column, _Join
1112

@@ -141,6 +142,11 @@ def test_query_tap(self):
141142
Simbad.clear_cache()
142143
assert _cached_query_tap.cache_info().currsize == 0
143144

145+
def test_empty_response_warns(self):
146+
with pytest.warns(NoResultsWarning, match="The request executed correctly, but *"):
147+
# a catalog that does not exists should return an empty response
148+
Simbad.query_catalog("unknown_catalog")
149+
144150
# ----------------------------------
145151

146152
def test_simbad_list_tables(self):

0 commit comments

Comments
 (0)