Skip to content

Commit

Permalink
doc: make the error message state the two possible causes for failure
Browse files Browse the repository at this point in the history
either the catalog is not available (no coordinates or typo in the name) or the user has to specify colRa and colDec
  • Loading branch information
ManonMarchand committed Jan 7, 2025
1 parent aeccd83 commit fcbaff0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ xmatch
- Fix xmatch query for two local tables. The second table was written over the first one,
resulting in a confusing "missing cat1" error. [#3116]

- Make the error message clearer about VizieR tables not available for
crossmatching [#3168]


0.4.7 (2024-03-08)
==================
Expand Down
7 changes: 6 additions & 1 deletion astroquery/xmatch/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,12 @@ def _prepare_sending_table(self, cat_index, payload, kwargs, cat, colRA, colDec)

if not self.is_table_available(cat):
if ((colRA is None) or (colDec is None)):
raise ValueError('Specify the name of the RA/Dec columns in the input table.')
raise ValueError(

Check warning on line 149 in astroquery/xmatch/core.py

View check run for this annotation

Codecov / codecov/patch

astroquery/xmatch/core.py#L149

Added line #L149 was not covered by tests
f"'{cat}' is not available on the XMatch server.If you are "
"using a VizieR table name, note that only tables with "
"coordinates are available on the XMatch server. If you are "
f"using a local table, the arguments 'colRA{cat_index}' and "
f"'colDec{cat_index}' must be provided.")
# if `cat1` is not a VizieR table,
# it is assumed it's either a URL or an uploaded table
payload['colRA{0}'.format(cat_index)] = colRA
Expand Down
22 changes: 14 additions & 8 deletions astroquery/xmatch/tests/test_xmatch_remote.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
from pathlib import Path
import os
from pathlib import Path
import re
import sys

from numpy.testing import assert_allclose
import pytest
import requests
from requests import ReadTimeout
from numpy.testing import assert_allclose

from astropy.coordinates import SkyCoord
from astroquery.exceptions import InvalidQueryError
from astropy.table import Table
from astropy.units import arcsec, arcmin

from astropy.coordinates import SkyCoord

try:
from regions import CircleSkyRegion
except ImportError:
pass

from astroquery.exceptions import InvalidQueryError
from ...xmatch import XMatch


Expand Down Expand Up @@ -126,9 +127,14 @@ def test_xmatch_query_with_cone_area(self, xmatch):
def test_xmatch_invalid_query(self, xmatch):
input_table = Table.read(DATA_DIR / "posList.csv", format="ascii.csv")
# columns in input table and kwargs are not matching

with pytest.raises(InvalidQueryError) as err:
with pytest.raises(InvalidQueryError,
match='Column name "DEC" not found in table metadata'):
xmatch.query(input_table, cat2='vizier:II/246/out', max_distance=5 * arcsec,
colRA1='ra', colDec1='DEC')

assert 'Column name "DEC" not found in table metadata' in str(err)
def test_table_not_available(self, xmatch):
cat1 = "vizier:J/A+A/331/81/table2"
cat2 = "blabla"
# reproduces #1464
with pytest.raises(ValueError, match=f"'{re.escape(cat1)}' is not available *"):
xmatch.query_async(cat1=cat1, cat2=cat2, max_distance=5 * arcsec)

0 comments on commit fcbaff0

Please sign in to comment.