Skip to content

Commit 500ed06

Browse files
committed
Merge pull request #431 from keflavich/vizier/max_catalogs
Vizier query fails to parse
2 parents 128628d + 36afc69 commit 500ed06

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

astroquery/vizier/core.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ def keywords(self, value):
123123
def keywords(self):
124124
self._keywords = None
125125

126-
def find_catalogs(self, keywords, include_obsolete=False, verbose=False):
126+
def find_catalogs(self, keywords, include_obsolete=False, verbose=False,
127+
max_catalogs=None):
127128
"""
128129
Search Vizier for catalogs based on a set of keywords, e.g. author name
129130
@@ -136,6 +137,9 @@ def find_catalogs(self, keywords, include_obsolete=False, verbose=False):
136137
only the catalogues characterized by all the words are selected."
137138
include_obsolete : bool, optional
138139
If set to True, catalogs marked obsolete will also be returned.
140+
max_catalogs : int or None
141+
The maximum number of catalogs to return. If ``None``, all
142+
catalogs will be returned.
139143
140144
Returns
141145
-------
@@ -159,10 +163,15 @@ def find_catalogs(self, keywords, include_obsolete=False, verbose=False):
159163
keywords = " ".join(keywords)
160164

161165
data_payload = {'-words': keywords, '-meta.all': 1}
166+
if max_catalogs is not None:
167+
data_payload['-meta.max'] = max_catalogs
162168
response = self._request(method='POST',
163169
url=self._server_to_url(),
164170
data=data_payload,
165171
timeout=self.TIMEOUT)
172+
if 'STOP, Max. number of RESOURCE reached' in response.content:
173+
raise ValueError("Maximum number of catalogs exceeded. Try setting max_catalogs "
174+
"to a large number and try again")
166175
result = self._parse_result(response, verbose=verbose, get_catalog_names=True)
167176

168177
# Filter out the obsolete catalogs, unless requested

astroquery/vizier/tests/test_vizier_remote.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Licensed under a 3-clause BSD style license - see LICENSE.rst
22

3-
from astropy.tests.helper import remote_data
3+
from astropy.tests.helper import remote_data,pytest
44
import astropy.units as u
5+
from astropy import coordinates
56
from ... import vizier
67
from ...utils import commons
78
import requests
@@ -59,8 +60,8 @@ def test_query_two_wavelengths(self):
5960
column_filters={"Vmag":">10"}, keywords=["optical", "radio"])
6061
v.query_object('M 31')
6162

62-
def regressiontest_invalidtable(self):
63-
V = Vizier(columns=['all'], ucd='(spect.dopplerVeloc*|phys.veloc*)',
63+
def test_regressiontest_invalidtable(self):
64+
V = vizier.core.Vizier(columns=['all'], ucd='(spect.dopplerVeloc*|phys.veloc*)',
6465
keywords=['Radio', 'IR'], row_limit=5000)
6566
C = coordinates.SkyCoord(359.61687 * u.deg, -0.242457 * u.deg, frame='galactic')
6667

@@ -79,3 +80,14 @@ def test_multicoord(self):
7980
assert len(result) >= 5
8081
assert 'I/239/hip_main' in result.keys()
8182
assert result['I/239/hip_main']['HIP'] == 98298
83+
84+
def test_findcatalog_maxcatalog(self):
85+
V = vizier.core.Vizier()
86+
cats = V.find_catalogs('eclipsing binary', max_catalogs=5000)
87+
assert len(cats) >= 468
88+
89+
#with pytest.raises(ValueError) as exc:
90+
# V.find_catalogs('eclipsing binary')
91+
#assert str(exc.value)==("Maximum number of catalogs exceeded."
92+
# " Try setting max_catalogs "
93+
# "to a large number and try again")

0 commit comments

Comments
 (0)