Skip to content

Commit

Permalink
Merge pull request #3068 from cds-astro/add-emtpy-response-warning
Browse files Browse the repository at this point in the history
[SIMBAD] Add emtpy response warning
  • Loading branch information
bsipocz authored Jul 16, 2024
2 parents cc25c37 + 31ca364 commit 53e636f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 27 deletions.
15 changes: 11 additions & 4 deletions astroquery/simbad/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from astroquery.query import BaseVOQuery
from astroquery.utils import commons
from astroquery.exceptions import LargeQueryWarning
from astroquery.exceptions import LargeQueryWarning, NoResultsWarning
from astroquery.simbad.utils import (_catch_deprecated_fields_with_arguments,
_wildcard_to_regexp, CriteriaTranslator,
query_criteria_fields)
Expand Down Expand Up @@ -1397,7 +1397,7 @@ def _query(self, top, columns, joins, criteria, from_table="basic",
`~astropy.table.Table`
The result of the query to SIMBAD.
"""
top = f" TOP {top}" if top != -1 else ""
top_part = f" TOP {top}" if top != -1 else ""

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

query = f"SELECT{top}{columns} FROM {from_table}{join}{criteria}"
query = f"SELECT{top_part}{columns} FROM {from_table}{join}{criteria}"

return self.query_tap(query, get_query_payload=get_query_payload, **uploads)
response = self.query_tap(query, get_query_payload=get_query_payload,
maxrec=self.hardlimit,
**uploads)

if len(response) == 0 and top != 0:
warnings.warn("The request executed correctly, but there was no data corresponding"
" to these criteria in SIMBAD", NoResultsWarning)
return response


Simbad = SimbadClass()
12 changes: 11 additions & 1 deletion astroquery/simbad/tests/test_simbad.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from ... import simbad
from .test_simbad_remote import multicoords
from astroquery.exceptions import LargeQueryWarning
from astroquery.exceptions import LargeQueryWarning, NoResultsWarning


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


@pytest.mark.usefixtures("_mock_simbad_class")
def test_empty_response_warns(monkeypatch):
# return something of length zero
monkeypatch.setattr(simbad.core.Simbad, "query_tap", lambda _, get_query_payload, maxrec: [])
msg = ("The request executed correctly, but there was no data corresponding to these"
" criteria in SIMBAD")
with pytest.warns(NoResultsWarning, match=msg):
simbad.core.Simbad.query_catalog("unknown_catalog")


# ---------------------------------------------------
# Test the adql string for query_tap helper functions
# ---------------------------------------------------
Expand Down
6 changes: 6 additions & 0 deletions astroquery/simbad/tests/test_simbad_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from astropy.utils.exceptions import AstropyDeprecationWarning
from astropy.table import Table

from astroquery.exceptions import NoResultsWarning
from astroquery.simbad import Simbad
from astroquery.simbad.core import _cached_query_tap, _Column, _Join

Expand Down Expand Up @@ -141,6 +142,11 @@ def test_query_tap(self):
Simbad.clear_cache()
assert _cached_query_tap.cache_info().currsize == 0

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

# ----------------------------------

def test_simbad_list_tables(self):
Expand Down
45 changes: 23 additions & 22 deletions docs/simbad/simbad.rst
Original file line number Diff line number Diff line change
Expand Up @@ -467,28 +467,29 @@ with:
>>> from astroquery.simbad import Simbad
>>> Simbad.list_votable_fields()[["name", "description"]]
<Table length=115>
name description
object object
------------- ----------------------------------------------------------------------------
mesDiameter Collection of stellar diameters.
mesPM Collection of proper motions.
mesISO Infrared Space Observatory (ISO) observing log.
mesSpT Collection of spectral types.
allfluxes all flux/magnitudes U,B,V,I,J,H,K,u_,g_,r_,i_,z_
ident Identifiers of an astronomical object
flux Magnitude/Flux information about an astronomical object
mesPLX Collection of trigonometric parallaxes.
otypedef all names and definitions for the object types
... ...
u Magnitude SDSS u
g Magnitude SDSS g
r Magnitude SDSS r
i Magnitude SDSS i
z Magnitude SDSS z
G Magnitude Gaia G
F150W JWST NIRCam F150W
F200W JWST NIRCam F200W
F444W JWST NIRCan F444W
name description
object object
----------- -------------------------------------------------------
mesDiameter Collection of stellar diameters.
mesPM Collection of proper motions.
mesISO Infrared Space Observatory (ISO) observing log.
mesSpT Collection of spectral types.
allfluxes all flux/magnitudes U,B,V,I,J,H,K,u_,g_,r_,i_,z_
ident Identifiers of an astronomical object
flux Magnitude/Flux information about an astronomical object
mesPLX Collection of trigonometric parallaxes.
otypedef all names and definitions for the object types
... ...
K Magnitude K
u Magnitude SDSS u
g Magnitude SDSS g
r Magnitude SDSS r
i Magnitude SDSS i
z Magnitude SDSS z
G Magnitude Gaia G
F150W JWST NIRCam F150W
F200W JWST NIRCam F200W
F444W JWST NIRCan F444W

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

0 comments on commit 53e636f

Please sign in to comment.