Skip to content

Commit 886817e

Browse files
authored
Merge pull request #2980 from cds-astro/fix-error-message-catalog-not-found
[vizier] raise a meaningful error message when no catalog is found in get_catalog_metadata
2 parents 9d172db + dcddaa7 commit 886817e

File tree

5 files changed

+34
-4
lines changed

5 files changed

+34
-4
lines changed

CHANGES.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ mpc
1313

1414
- Parse star catalog information when querying observations database [#2957]
1515

16+
vizier
17+
^^^^^^
18+
19+
- Change the type of raised error when the catalog is not found in ``Vizier.get_catalog_metadata``
20+
from ``IndexError`` to ``EmptyResponseError`` [#2980]
21+
1622

1723
Infrastructure, Utility and Other Changes and Additions
1824
-------------------------------------------------------

astroquery/utils/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from .class_or_instance import class_or_instance
88
from .commons import (parse_coordinates, TableList, suppress_vo_warnings,
99
validate_email, ASTROPY_LT_4_3, ASTROPY_LT_5_0,
10-
ASTROPY_LT_5_1)
10+
ASTROPY_LT_5_1, ASTROPY_LT_6_0)
1111
from .process_asyncs import async_to_sync
1212
from .docstr_chompers import prepend_docstr_nosections
1313
from .cleanup_downloads import cleanup_saved_downloads
@@ -22,6 +22,7 @@
2222
'ASTROPY_LT_4_3',
2323
'ASTROPY_LT_5_0',
2424
'ASTROPY_LT_5_1',
25+
'ASTROPY_LT_6_0',
2526
"async_to_sync",
2627
"prepend_docstr_nosections",
2728
"cleanup_saved_downloads"]

astroquery/utils/commons.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@
3131
'validate_email',
3232
'ASTROPY_LT_4_3',
3333
'ASTROPY_LT_5_0',
34-
'ASTROPY_LT_5_1']
34+
'ASTROPY_LT_5_1',
35+
'ASTROPY_LT_6_0']
3536

3637
ASTROPY_LT_4_3 = not minversion('astropy', '4.3')
3738
ASTROPY_LT_5_0 = not minversion('astropy', '5.0')
38-
3939
ASTROPY_LT_5_1 = not minversion('astropy', '5.1')
40+
ASTROPY_LT_6_0 = not minversion('astropy', '6.0')
4041

4142

4243
def parse_coordinates(coordinates):

astroquery/vizier/core.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from ..utils import async_to_sync
2424
from ..utils import schema
2525
from . import conf
26-
from ..exceptions import TableParseError
26+
from ..exceptions import TableParseError, EmptyResponseError
2727

2828

2929
__all__ = ['Vizier', 'VizierClass']
@@ -345,6 +345,9 @@ def get_catalog_metadata(self, *, catalog=None, get_query_payload=False):
345345
if get_query_payload:
346346
return metadata
347347
result = metadata.execute().to_table()
348+
if len(result) == 0:
349+
raise EmptyResponseError(f"'{catalog}' was not found in VizieR. Valid catalog names "
350+
"often look like: 'IX/58', 'J/MNRAS/491/215', 'J/ApJS/256/33', etc.")
348351
# apply mask if the `alt_identifier` value is not a doi
349352
result["doi"].mask = True if "doi:" not in result["doi"][0] else False
350353
return result

astroquery/vizier/tests/test_vizier.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
import requests
44
from numpy import testing as npt
55
import pytest
6+
from pyvo import registry
67
from astropy.coordinates import SkyCoord
8+
import astropy.io.votable.tree as votree
79
from astropy.table import Table
810
import astropy.units as u
911

1012
from ... import vizier
13+
from ...exceptions import EmptyResponseError
1114
from ...utils import commons
1215
from astroquery.utils.mocks import MockResponse
1316
from .conftest import scalar_skycoord, vector_skycoord
@@ -271,3 +274,19 @@ def test_get_catalog_metadata(self):
271274
assert "WHERE ivoid = 'ivo://cds.vizier/test'" in request_dict["QUERY"]
272275
with pytest.raises(ValueError, match="No catalog name was provided"):
273276
vizier.core.Vizier().get_catalog_metadata()
277+
278+
def test_get_catalog_metadata_empty_result(self, monkeypatch):
279+
"""Checks that an empty result raises a meaningful error."""
280+
v = vizier.core.Vizier(catalog="should_return_empty_result")
281+
282+
def return_empty_votable(_):
283+
if commons.ASTROPY_LT_6_0:
284+
table = votree.Table(votree.VOTableFile())
285+
else:
286+
table = votree.TableElement(votree.VOTableFile())
287+
return table
288+
289+
monkeypatch.setattr(registry.regtap.RegistryQuery, "execute",
290+
return_empty_votable)
291+
with pytest.raises(EmptyResponseError, match="'*' was not found in VizieR*"):
292+
v.get_catalog_metadata()

0 commit comments

Comments
 (0)