Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix for pagesize and page parameters in catalogs.query_criteria() #3065

Merged
merged 2 commits into from
Jul 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ mast

- Add ``verbose`` parameter to modulate output in ``mast.observations.download_products`` method. [#3031]

- Fix bug in ``Catalogs.query_criteria()`` to use ``page`` and ``pagesize`` parameters correctly. [#3065]



0.4.7 (2024-03-08)
Expand Down
2 changes: 2 additions & 0 deletions astroquery/mast/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ def query_criteria_async(self, catalog, *, pagesize=None, page=None, **criteria)

Parameters
----------
catalog : str
The catalog to be queried.
pagesize : int, optional
Can be used to override the default pagesize.
E.g. when using a slow internet connection.
Expand Down
16 changes: 9 additions & 7 deletions astroquery/mast/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import numpy as np

from astropy.table import Table, MaskedColumn
from astropy.utils.decorators import deprecated_renamed_argument

from ..query import BaseQuery
from ..utils import async_to_sync
Expand Down Expand Up @@ -222,7 +223,8 @@ def _parse_result(self, response, verbose=False, data_key='data'):
return result_table

@class_or_instance
def service_request_async(self, service, params, page_size=None, page=None, use_json=False, **kwargs):
@deprecated_renamed_argument('page_size', 'pagesize', since='0.4.8')
def service_request_async(self, service, params, pagesize=None, page=None, use_json=False, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use a deprecation rename argument for this

"""
Given a MAST fabric service and parameters, builds and executes a fabric microservice catalog query.
See documentation `here <https://catalogs.mast.stsci.edu/docs/index.html>`__
Expand All @@ -234,7 +236,7 @@ def service_request_async(self, service, params, page_size=None, page=None, use_
The MAST catalogs service to query. Should be present in self.SERVICES
params : dict
JSON object containing service parameters.
page_size : int, optional
pagesize : int, optional
Default None.
Can be used to override the default pagesize (set in configs) for this query only.
E.g. when using a slow internet connection.
Expand Down Expand Up @@ -273,13 +275,13 @@ def service_request_async(self, service, params, page_size=None, page=None, use_
catalogs_request = []
if not page:
page = params.pop('page', None)
if not page_size:
page_size = params.pop('page_size', None)
if not pagesize:
pagesize = params.pop('pagesize', None)

if page is not None:
catalogs_request.append(('page', page))
if page_size is not None:
catalogs_request.append(('pagesize', page_size))
if pagesize is not None:
catalogs_request.append(('pagesize', pagesize))

if not use_json:
# Decompose filters, sort
Expand Down Expand Up @@ -331,7 +333,7 @@ def _build_catalogs_params(self, params):
if prop == 'format':
# Ignore format changes
continue
elif prop == 'page_size':
elif prop == 'pagesize':
catalog_params.extend(('pagesize', value))
elif prop == 'sort_by':
# Loop through each value if list
Expand Down
32 changes: 29 additions & 3 deletions astroquery/mast/tests/test_mast_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,14 @@ def test_mast_service_request(self):
'dec': 54.5,
'radius': 0.001}

result = Mast.service_request(service, params)
result = Mast.service_request(service, params, pagesize=10, page=2)

# Is result in the right format
assert isinstance(result, Table)

# Is result limited to ten rows
assert len(result) == 10

# Are the GALEX observations in the results table
assert "GALEX" in result['obs_collection']

Expand Down Expand Up @@ -532,15 +535,18 @@ def check_result(result, row, exp_values):
radius=0.01*u.deg, catalog="panstarrs",
table="mean")
row = np.where((result['objName'] == 'PSO J322.4622+12.1920') & (result['yFlags'] == 16777496))
second_id = result[1]['objID']
assert isinstance(result, Table)
np.testing.assert_allclose(result[row]['distance'], 0.039381703406789904)

result = Catalogs.query_region("322.49324 12.16683",
radius=0.01*u.deg, catalog="panstarrs",
table="mean",
page_size=3)
pagesize=1,
page=2)
assert isinstance(result, Table)
assert len(result) == 3
assert len(result) == 1
assert second_id == result[0]['objID']

result = Catalogs.query_region("158.47924 -7.30962",
radius=in_radius,
Expand Down Expand Up @@ -588,6 +594,16 @@ def check_result(result, exp_values):
radius=.001,
catalog="TIC")
check_result(result, {'ID': '1305764225'})
second_id = result[1]['ID']

result = Catalogs.query_object("M10",
radius=.001,
catalog="TIC",
pagesize=1,
page=2)
assert isinstance(result, Table)
assert len(result) == 1
assert second_id == result[0]['ID']

result = Catalogs.query_object("M10",
radius=.001,
Expand Down Expand Up @@ -681,6 +697,16 @@ def check_result(result, exp_vals):
Bmag=[30, 50],
objType="STAR")
check_result(result, {'ID': '81609218'})
second_id = result[1]['ID']

result = Catalogs.query_criteria(catalog="Tic",
Bmag=[30, 50],
objType="STAR",
pagesize=1,
page=2)
assert isinstance(result, Table)
assert len(result) == 1
assert second_id == result[0]['ID']

result = Catalogs.query_criteria(catalog="ctl",
Tmag=[10.5, 11],
Expand Down
Loading