Skip to content

Commit 92aac51

Browse files
committed
Define unlimited_max_rec decorator
1 parent fb0894a commit 92aac51

File tree

2 files changed

+37
-25
lines changed

2 files changed

+37
-25
lines changed

astroquery/eso/core.py

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import base64
1212
import email
13+
import functools
1314
import json
1415
import os
1516
import os.path
@@ -77,6 +78,26 @@ def ist_table(instrument_name):
7778
return f"ist.{instrument_name}"
7879

7980

81+
def unlimited_max_rec(func):
82+
"""
83+
decorator to overwrite the ROW LIMIT
84+
for specific queries
85+
"""
86+
@functools.wraps(func)
87+
def wrapper(self, *args, **kwargs):
88+
if not isinstance(self, EsoClass):
89+
raise ValueError(f"Expecting EsoClass, found {type(self)}")
90+
91+
tmpvar = self.ROW_LIMIT
92+
try:
93+
self.ROW_LIMIT = sys.maxsize
94+
result = func(self, *args, **kwargs)
95+
finally:
96+
self.ROW_LIMIT = tmpvar
97+
return result
98+
return wrapper
99+
100+
80101
class EsoClass(QueryWithLogin):
81102
ROW_LIMIT = conf.row_limit
82103
USERNAME = conf.username
@@ -224,26 +245,23 @@ def query_tap_service(self,
224245

225246
return table_to_return
226247

248+
@unlimited_max_rec
227249
def list_instruments(self) -> List[str]:
228250
""" List all the available instrument-specific queries offered by the ESO archive.
229251
230252
Returns
231253
-------
232254
instrument_list : list of strings
233255
"""
234-
tmpvar = self.ROW_LIMIT
235-
self.ROW_LIMIT = sys.maxsize
236-
try:
237-
if self._instruments is None:
238-
self._instruments = []
239-
query_str = ("select table_name from TAP_SCHEMA.tables "
240-
"where schema_name='ist' order by table_name")
241-
res = self.query_tap_service(query_str)["table_name"].data
242-
self._instruments = list(map(lambda x: x.split(".")[1], res))
243-
finally:
244-
self.ROW_LIMIT = tmpvar
256+
if self._instruments is None:
257+
self._instruments = []
258+
query_str = ("select table_name from TAP_SCHEMA.tables "
259+
"where schema_name='ist' order by table_name")
260+
res = self.query_tap_service(query_str)["table_name"].data
261+
self._instruments = list(map(lambda x: x.split(".")[1], res))
245262
return self._instruments
246263

264+
@unlimited_max_rec
247265
def list_collections(self) -> List[str]:
248266
""" List all the available collections (phase 3) in the ESO archive.
249267
@@ -254,21 +272,16 @@ def list_collections(self) -> List[str]:
254272
Defaults to True. If set overrides global caching behavior.
255273
See :ref:`caching documentation <astroquery_cache>`.
256274
"""
257-
tmpvar = self.ROW_LIMIT
258-
self.ROW_LIMIT = sys.maxsize
259-
try:
260-
if self._collections is None:
261-
self._collections = []
262-
t = EsoNames.phase3_table
263-
c = EsoNames.phase3_collections_column
264-
query_str = f"select distinct {c} from {t}"
265-
res = self.query_tap_service(query_str)[c].data
266-
267-
self._collections = list(res)
268-
finally:
269-
self.ROW_LIMIT = tmpvar
275+
if self._collections is None:
276+
self._collections = []
277+
t = EsoNames.phase3_table
278+
c = EsoNames.phase3_collections_column
279+
query_str = f"select distinct {c} from {t}"
280+
res = self.query_tap_service(query_str)[c].data
281+
self._collections = list(res)
270282
return self._collections
271283

284+
@unlimited_max_rec
272285
def print_table_help(self, table_name: str) -> None:
273286
"""
274287
Prints the columns contained in a given table

astroquery/eso/tests/test_eso_remote.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"""
1010

1111
from collections import Counter
12-
import numpy as np
1312
import pytest
1413

1514
from astropy.table import Table

0 commit comments

Comments
 (0)