Skip to content

Commit 130e01c

Browse files
committed
fix: allow to ommit vizier: in vizier table names
this makes the API less strict to use
1 parent ed9d418 commit 130e01c

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

CHANGES.rst

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

1414
- Fixed InvalidTableError for DI_STARS_EXEP and TD tables. [#3189]
1515

16+
xmatch
17+
^^^^^^
18+
19+
- the API is more flexible: you can now ommit the ``vizier:`` before the catalog name
20+
when crossmatching with a vizier table [#3194]
21+
1622

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

astroquery/xmatch/core.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ def _prepare_sending_table(self, cat_index, payload, kwargs, cat, colRA, colDec)
126126
'''
127127
catstr = 'cat{0}'.format(cat_index)
128128
if isinstance(cat, str):
129+
if (self.is_table_available(cat) and not cat.startswith("vizier:")):
130+
# if we detect that the given name is a vizier table, we can make
131+
# it comply to the API, see issue #3191
132+
cat = f"vizier:{cat}"
129133
payload[catstr] = cat
130134
else:
131135
# create the dictionary of uploaded files
@@ -181,7 +185,7 @@ def is_table_available(self, table_id):
181185
if not isinstance(table_id, str):
182186
return False
183187

184-
if (table_id[:7] == 'vizier:'):
188+
if table_id.startswith('vizier:'):
185189
table_id = table_id[7:]
186190

187191
return table_id in self.get_available_tables()

astroquery/xmatch/tests/test_xmatch.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,33 @@ def test_table_not_available(monkeypatch):
124124
# reproduces #1464
125125
with pytest.raises(ValueError, match=f"'{re.escape(cat1)}' is not available *"):
126126
xm.query_async(cat1=cat1, cat2=cat2, max_distance=5 * arcsec)
127+
128+
129+
def test_prepare_sending_tables(monkeypatch):
130+
xm = XMatch()
131+
monkeypatch.setattr(xm, '_request', request_mockreturn)
132+
133+
# if it's a valid vizier table, prepend vizier:
134+
payload = {}
135+
xm._prepare_sending_table(1, payload, {}, "II/316/gps6", None, None)
136+
assert payload == {'cat1': 'vizier:II/316/gps6'}
137+
# also works if vizier: is already given by the user
138+
payload = {}
139+
xm._prepare_sending_table(1, payload, {}, "vizier:II/316/gps6", None, None)
140+
assert payload == {'cat1': 'vizier:II/316/gps6'}
141+
142+
# otherwise colRa1 and colDec1 have to be given
143+
with pytest.raises(ValueError, match="'test' is not available on the XMatch server."):
144+
xm._prepare_sending_table(1, payload, {}, "test", None, None)
145+
payload = {}
146+
# this mimics the url case
147+
xm._prepare_sending_table(1, payload, {}, "test", "ra", "dec")
148+
assert payload == {'cat1': 'test', 'colRA1': 'ra', 'colDec1': 'dec'}
149+
150+
# if cat is not a string, then the payload has to include the file
151+
payload = {}
152+
kwargs = {}
153+
cat = Table({'a': [0, 1, 2], 'b': [3, 4, 5]})
154+
xm._prepare_sending_table(1, payload, kwargs, cat, "a", "b")
155+
assert payload == {'colRA1': 'a', 'colDec1': 'b'}
156+
assert kwargs == {'files': {'cat1': ('cat1.csv', 'a,b\n0,3\n1,4\n2,5\n')}}

astroquery/xmatch/tests/test_xmatch_remote.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ def test_xmatch_query_astropy_table(self, xmatch, remote_table):
112112
else:
113113
assert_allclose(table[col], remote_table[col])
114114

115+
def test_two_remote_tables(self, xmatch):
116+
# we also test that omitting vizier: works
117+
result = xmatch.query("simbad", "J/A+A/113/61/table2", max_distance=0.5*arcsec)
118+
assert {"main_id", "MH"}.issubset(result.colnames)
119+
assert all(result["angDist"] < 0.5)
120+
115121
@pytest.mark.skipif('regions' not in sys.modules,
116122
reason="requires astropy-regions")
117123
def test_xmatch_query_with_cone_area(self, xmatch):

0 commit comments

Comments
 (0)