Skip to content

Commit 6120d8e

Browse files
committed
Adding cache kwarg, use cache=False in tests
1 parent 7609419 commit 6120d8e

File tree

4 files changed

+49
-24
lines changed

4 files changed

+49
-24
lines changed

CHANGES.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ heasarc
3636
- Add alternative instance of HEASARC Server, maintained by
3737
INTEGRAL Science Data Center. [#1988]
3838

39+
irsa
40+
^^^^
41+
42+
- Adding ``cache`` kwarg to the class methods to be able to control the use
43+
of local cache. [#2092]
44+
3945
nasa_exoplanet_archive
4046
^^^^^^^^^^^^^^^^^^^^^^
4147

astroquery/irsa/core.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ class IrsaClass(BaseQuery):
125125

126126
def query_region(self, coordinates=None, catalog=None, spatial='Cone',
127127
radius=10 * u.arcsec, width=None, polygon=None,
128-
get_query_payload=False, verbose=False, selcols=None):
128+
get_query_payload=False, verbose=False, selcols=None,
129+
cache=True):
129130
"""
130131
This function can be used to perform either cone, box, polygon or
131132
all-sky search in the catalogs hosted by the NASA/IPAC Infrared
@@ -169,7 +170,8 @@ def query_region(self, coordinates=None, catalog=None, spatial='Cone',
169170
conform to the standard. Defaults to `False`.
170171
selcols : str, optional
171172
Target column list with value separated by a comma(,)
172-
173+
cache : bool, optional
174+
Use local cache when set to `True`.
173175
174176
Returns
175177
-------
@@ -180,15 +182,15 @@ def query_region(self, coordinates=None, catalog=None, spatial='Cone',
180182
spatial=spatial, radius=radius,
181183
width=width, polygon=polygon,
182184
get_query_payload=get_query_payload,
183-
selcols=selcols)
185+
selcols=selcols, cache=cache)
184186
if get_query_payload:
185187
return response
186188
return self._parse_result(response, verbose=verbose)
187189

188190
def query_region_async(self, coordinates=None, catalog=None,
189191
spatial='Cone', radius=10 * u.arcsec, width=None,
190192
polygon=None, get_query_payload=False,
191-
selcols=None):
193+
selcols=None, cache=True):
192194
"""
193195
This function serves the same purpose as
194196
:meth:`~astroquery.irsa.IrsaClass.query_region`, but returns the raw
@@ -228,6 +230,8 @@ def query_region_async(self, coordinates=None, catalog=None,
228230
Defaults to `False`.
229231
selcols : str, optional
230232
Target column list with value separated by a comma(,)
233+
cache : bool, optional
234+
Use local cache when set to `True`.
231235
232236
Returns
233237
-------
@@ -246,7 +250,8 @@ def query_region_async(self, coordinates=None, catalog=None,
246250
if get_query_payload:
247251
return request_payload
248252
response = self._request("GET", url=Irsa.IRSA_URL,
249-
params=request_payload, timeout=Irsa.TIMEOUT)
253+
params=request_payload, timeout=Irsa.TIMEOUT,
254+
cache=cache)
250255
return response
251256

252257
def _parse_spatial(self, spatial, coordinates, radius=None, width=None,
@@ -410,33 +415,42 @@ def _parse_result(self, response, verbose=False):
410415

411416
return table
412417

413-
def list_catalogs(self):
418+
419+
def list_catalogs(self, cache=False):
414420
"""
415421
Return a dictionary of the catalogs in the IRSA Gator tool.
416422
423+
Parameters
424+
----------
425+
cache : bool
426+
Use local cache when set to `True`. Default is `False`.
427+
417428
Returns
418429
-------
419430
catalogs : dict
420431
A dictionary of catalogs where the key indicates the catalog
421432
name to be used in query functions, and the value is the verbose
422433
description of the catalog.
434+
423435
"""
424436
response = self._request("GET", url=Irsa.GATOR_LIST_URL,
425-
params=dict(mode='xml'), timeout=Irsa.TIMEOUT)
437+
params=dict(mode='xml'), cache=cache,
438+
timeout=Irsa.TIMEOUT)
426439

427440
root = tree.fromstring(response.content)
428441
catalogs = {}
429442
for catalog in root.findall('catalog'):
430443
catname = catalog.find('catname').text
431444
desc = catalog.find('desc').text
432445
catalogs[catname] = desc
446+
433447
return catalogs
434448

435-
def print_catalogs(self):
449+
def print_catalogs(self, cache=False):
436450
"""
437451
Display a table of the catalogs in the IRSA Gator tool.
438452
"""
439-
catalogs = self.list_catalogs()
453+
catalogs = self.list_catalogs(cache=cache)
440454
for catname in catalogs:
441455
print("{:30s} {:s}".format(catname, catalogs[catname]))
442456

astroquery/irsa/tests/test_irsa.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def patch_get(request):
3939
return mp
4040

4141

42-
def get_mockreturn(method, url, params=None, timeout=10, **kwargs):
42+
def get_mockreturn(method, url, params=None, timeout=10, cache=False, **kwargs):
4343
filename = data_path(DATA_FILES[params['spatial']])
4444
content = open(filename, 'rb').read()
4545
return MockResponse(content, **kwargs)

astroquery/irsa/tests/test_irsa_remote.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from astropy.table import Table
77
from astropy.coordinates import SkyCoord
88

9-
from ... import irsa
9+
from astroquery.irsa import Irsa
1010

1111

1212
OBJ_LIST = ["m31", "00h42m44.330s +41d16m07.50s",
@@ -16,41 +16,46 @@
1616

1717
@pytest.mark.remote_data
1818
class TestIrsa:
19-
2019
def test_query_region_cone_async(self):
21-
response = irsa.core.Irsa.query_region_async(
22-
'm31', catalog='fp_psc', spatial='Cone', radius=2 * u.arcmin)
20+
response = Irsa.query_region_async(
21+
'm31', catalog='fp_psc', spatial='Cone', radius=2 * u.arcmin, cache=False)
2322
assert response is not None
2423

2524
def test_query_region_cone(self):
26-
result = irsa.core.Irsa.query_region(
27-
'm31', catalog='fp_psc', spatial='Cone', radius=2 * u.arcmin)
25+
result = Irsa.query_region(
26+
'm31', catalog='fp_psc', spatial='Cone', radius=2 * u.arcmin, cache=False)
2827
assert isinstance(result, Table)
2928

3029
def test_query_region_box_async(self):
31-
response = irsa.core.Irsa.query_region_async(
30+
response = Irsa.query_region_async(
3231
"00h42m44.330s +41d16m07.50s", catalog='fp_psc', spatial='Box',
33-
width=2 * u.arcmin)
32+
width=2 * u.arcmin, cache=False)
3433
assert response is not None
3534

3635
def test_query_region_box(self):
37-
result = irsa.core.Irsa.query_region(
36+
result = Irsa.query_region(
3837
"00h42m44.330s +41d16m07.50s", catalog='fp_psc', spatial='Box',
39-
width=2 * u.arcmin)
38+
width=2 * u.arcmin, cache=False)
4039
assert isinstance(result, Table)
4140

4241
def test_query_region_async_polygon(self):
4342
polygon = [SkyCoord(ra=10.1, dec=10.1, unit=(u.deg, u.deg)),
4443
SkyCoord(ra=10.0, dec=10.1, unit=(u.deg, u.deg)),
4544
SkyCoord(ra=10.0, dec=10.0, unit=(u.deg, u.deg))]
46-
response = irsa.core.Irsa.query_region_async(
47-
"m31", catalog="fp_psc", spatial="Polygon", polygon=polygon)
45+
response = Irsa.query_region_async(
46+
"m31", catalog="fp_psc", spatial="Polygon", polygon=polygon, cache=False)
4847

4948
assert response is not None
5049

5150
def test_query_region_polygon(self):
5251
polygon = [(10.1, 10.1), (10.0, 10.1), (10.0, 10.0)]
53-
result = irsa.core.Irsa.query_region(
54-
"m31", catalog="fp_psc", spatial="Polygon", polygon=polygon)
52+
result = Irsa.query_region(
53+
"m31", catalog="fp_psc", spatial="Polygon", polygon=polygon, cache=False)
5554

5655
assert isinstance(result, Table)
56+
57+
def test_list_catalogs(self):
58+
catalogs = Irsa.list_catalogs(cache=False)
59+
# Number of available catalogs may change over time, test only for significant drop.
60+
# (at the time of writing there are 587 catalogs in the list).
61+
assert len(catalogs) > 500

0 commit comments

Comments
 (0)