Skip to content

Commit 4e6f0ee

Browse files
committed
maint: switch from meta.all to meta to reduce response size
we don't lose information, but ASU-style queries cannot get a dictionnary in the POST request's data
1 parent dd7b0cd commit 4e6f0ee

File tree

2 files changed

+29
-29
lines changed

2 files changed

+29
-29
lines changed

astroquery/vizier/core.py

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -205,44 +205,44 @@ def find_catalogs(self, keywords, *, include_obsolete=False, verbose=False,
205205
Examples
206206
--------
207207
>>> from astroquery.vizier import Vizier
208-
>>> catalog_list = Vizier.find_catalogs('Kang W51') # doctest: +REMOTE_DATA +IGNORE_WARNINGS
209-
>>> catalog_list # doctest: +REMOTE_DATA +IGNORE_OUTPUT
210-
OrderedDict([('J/ApJ/684/1143', </>), ('J/ApJ/736/87', </>) ... ])
211-
>>> print({k:v.description for k,v in catalog_list.items()}) # doctest: +REMOTE_DATA +IGNORE_OUTPUT
212-
{'J/ApJ/684/1143': 'BHB candidates in the Milky Way (Xue+, 2008)',
213-
'J/ApJ/736/87': 'Abundances in G-type stars with exoplanets (Kang+, 2011)',
214-
'J/ApJ/738/79': "SDSS-DR8 BHB stars in the Milky Way's halo (Xue+, 2011)",
215-
'J/ApJ/760/12': 'LIGO/Virgo gravitational-wave (GW) bursts with GRBs (Abadie+, 2012)',
216-
...}
208+
>>> catalog_list = Vizier.find_catalogs('Mars') # doctest: +REMOTE_DATA +IGNORE_WARNINGS
209+
>>> for k, v in catalog_list.items(): # doctest: +REMOTE_DATA +IGNORE_OUTPUT
210+
... print(k, ":", v.description)
211+
J/A+A/572/A104 : Astrometric obs. of Phobos and Deimos in 1971 (Robert+, 2014)
212+
J/A+A/488/361 : Mars Express astrometric observations of Phobos (Willner+, 2008)
213+
J/A+A/603/A55 : WISE/NEOWISE Mars-crossing asteroids (Ali-Lagoa+, 2017)
214+
J/A+A/545/A144 : Astrometric observations of Deimos (Pasewaldt+, 2012)
215+
...
217216
"""
218217

219-
if isinstance(keywords, list):
220-
keywords = " ".join(keywords)
218+
# Note to devs: The ASU convention (http://vizier.u-strasbg.fr/doc/asu.html) has
219+
# parameters without values. This is a bit different from POST requests that have
220+
# key/values pairs. This is why we send a string formatted for ASU instead of a
221+
# dictionary in the POST request here.
221222

222-
data_payload = {'-words': keywords, '-meta.all': 1}
223+
if isinstance(keywords, list):
224+
keywords = "+".join(keywords)
225+
keywords = keywords.replace(" ", "+")
223226

224-
data_payload['-ucd'] = self.ucd
227+
data_payload = {'-words': keywords, "-meta": None}
225228

226229
if max_catalogs is not None:
227230
data_payload['-meta.max'] = max_catalogs
228-
response = self._request(
229-
method='POST', url=self._server_to_url(return_type=return_type),
230-
data=data_payload, timeout=self.TIMEOUT)
231231

232-
if 'STOP, Max. number of RESOURCE reached' in response.text:
233-
raise ValueError("Maximum number of catalogs exceeded. Try "
234-
"setting max_catalogs to a large number and"
235-
" try again")
236-
result = self._parse_result(response, verbose=verbose,
237-
get_catalog_names=True)
232+
if include_obsolete:
233+
data_payload["-obsolete"] = None
234+
235+
if self.ucd != "":
236+
data_payload["ucd"] = self.ucd
237+
238+
params = "&".join([k if v is None else f"{k}={v}" for k, v in data_payload.items()])
238239

239-
# Filter out the obsolete catalogs, unless requested
240-
if include_obsolete is False:
241-
for key in list(result):
242-
for info in result[key].infos:
243-
if (info.name == 'status') and (info.value == 'obsolete'):
244-
del result[key]
240+
response = self._request(method='POST',
241+
url=self._server_to_url(return_type=return_type),
242+
data=params, timeout=self.TIMEOUT)
245243

244+
result = self._parse_result(response, verbose=verbose,
245+
get_catalog_names=True)
246246
return result
247247

248248
def get_catalogs_async(self, catalog, *, verbose=False, return_type='votable',

astroquery/vizier/tests/test_vizier.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def post_mockreturn(self, method, url, data=None, timeout=10, files=None,
5555
filename = data_path(VO_DATA[datad['-source']])
5656
elif '-words' in datad:
5757
# a find_catalog request/only metadata
58-
filename = data_path(VO_DATA['find_' + datad['-words']])
58+
filename = data_path(VO_DATA['find_' + datad['-words'].split("&")[0]])
5959

6060
with open(filename, 'rb') as infile:
6161
content = infile.read()

0 commit comments

Comments
 (0)