Skip to content

Commit 53e636f

Browse files
authored
Merge pull request #3068 from cds-astro/add-emtpy-response-warning
[SIMBAD] Add emtpy response warning
2 parents cc25c37 + 31ca364 commit 53e636f

File tree

4 files changed

+51
-27
lines changed

4 files changed

+51
-27
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):

docs/simbad/simbad.rst

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -467,28 +467,29 @@ with:
467467
>>> from astroquery.simbad import Simbad
468468
>>> Simbad.list_votable_fields()[["name", "description"]]
469469
<Table length=115>
470-
name description
471-
object object
472-
------------- ----------------------------------------------------------------------------
473-
mesDiameter Collection of stellar diameters.
474-
mesPM Collection of proper motions.
475-
mesISO Infrared Space Observatory (ISO) observing log.
476-
mesSpT Collection of spectral types.
477-
allfluxes all flux/magnitudes U,B,V,I,J,H,K,u_,g_,r_,i_,z_
478-
ident Identifiers of an astronomical object
479-
flux Magnitude/Flux information about an astronomical object
480-
mesPLX Collection of trigonometric parallaxes.
481-
otypedef all names and definitions for the object types
482-
... ...
483-
u Magnitude SDSS u
484-
g Magnitude SDSS g
485-
r Magnitude SDSS r
486-
i Magnitude SDSS i
487-
z Magnitude SDSS z
488-
G Magnitude Gaia G
489-
F150W JWST NIRCam F150W
490-
F200W JWST NIRCam F200W
491-
F444W JWST NIRCan F444W
470+
name description
471+
object object
472+
----------- -------------------------------------------------------
473+
mesDiameter Collection of stellar diameters.
474+
mesPM Collection of proper motions.
475+
mesISO Infrared Space Observatory (ISO) observing log.
476+
mesSpT Collection of spectral types.
477+
allfluxes all flux/magnitudes U,B,V,I,J,H,K,u_,g_,r_,i_,z_
478+
ident Identifiers of an astronomical object
479+
flux Magnitude/Flux information about an astronomical object
480+
mesPLX Collection of trigonometric parallaxes.
481+
otypedef all names and definitions for the object types
482+
... ...
483+
K Magnitude K
484+
u Magnitude SDSS u
485+
g Magnitude SDSS g
486+
r Magnitude SDSS r
487+
i Magnitude SDSS i
488+
z Magnitude SDSS z
489+
G Magnitude Gaia G
490+
F150W JWST NIRCam F150W
491+
F200W JWST NIRCam F200W
492+
F444W JWST NIRCan F444W
492493

493494
You can also access a single field description with
494495
`~astroquery.simbad.SimbadClass.get_field_description`

0 commit comments

Comments
 (0)