From 651866ee6f313b9e41c02e73d99c17bca2b83608 Mon Sep 17 00:00:00 2001 From: Eero Vaher Date: Tue, 26 Oct 2021 17:45:50 +0200 Subject: [PATCH 1/3] Simplify changing the row limit in Gaia queries It is now possible to specify the row limit of the `query_object` and `cone_search` families of functions with a keyword argument. It is now also possible to change the row limit through the `conf.ROW_LIMIT` configuration item at runtime. --- astroquery/gaia/core.py | 56 +++++++++++++++++------ astroquery/gaia/tests/test_gaia_remote.py | 11 ++--- astroquery/gaia/tests/test_gaiatap.py | 17 +++++++ docs/gaia/gaia.rst | 17 ++++--- 4 files changed, 75 insertions(+), 26 deletions(-) diff --git a/astroquery/gaia/core.py b/astroquery/gaia/core.py index 7170f72214..8b1a6202ce 100644 --- a/astroquery/gaia/core.py +++ b/astroquery/gaia/core.py @@ -41,7 +41,7 @@ class GaiaClass(TapPlus): MAIN_GAIA_TABLE = None MAIN_GAIA_TABLE_RA = conf.MAIN_GAIA_TABLE_RA MAIN_GAIA_TABLE_DEC = conf.MAIN_GAIA_TABLE_DEC - ROW_LIMIT = conf.ROW_LIMIT + ROW_LIMIT = None VALID_DATALINK_RETRIEVAL_TYPES = conf.VALID_DATALINK_RETRIEVAL_TYPES def __init__(self, tap_plus_conn_handler=None, @@ -356,7 +356,7 @@ def get_datalinks(self, ids, verbose=False): return self.__gaiadata.get_datalinks(ids=ids, verbose=verbose) def __query_object(self, coordinate, radius=None, width=None, height=None, - async_job=False, verbose=False, columns=[]): + async_job=False, verbose=False, columns=[], row_limit=None): """Launches a job TAP & TAP+ @@ -378,6 +378,10 @@ def __query_object(self, coordinate, radius=None, width=None, height=None, flag to display information about the process columns: list, optional, default [] if empty, all columns will be selected + row_limit : int, optional + The maximum number of retrieved rows. Will default to the value + provided by the configuration system if not set explicitly. The + value -1 removes the limit entirely. Returns ------- @@ -395,7 +399,7 @@ def __query_object(self, coordinate, radius=None, width=None, height=None, heightQuantity = self.__getQuantityInput(height, "height") widthDeg = widthQuantity.to(units.deg) heightDeg = heightQuantity.to(units.deg) - + row_limit = row_limit or self.ROW_LIMIT or conf.ROW_LIMIT if columns: columns = ','.join(map(str, columns)) else: @@ -424,7 +428,7 @@ def __query_object(self, coordinate, radius=None, width=None, height=None, ) ORDER BY dist ASC - """.format(**{'row_limit': "TOP {0}".format(self.ROW_LIMIT) if self.ROW_LIMIT > 0 else "", + """.format(**{'row_limit': "TOP {0}".format(row_limit) if row_limit > 0 else "", 'ra_column': self.MAIN_GAIA_TABLE_RA, 'dec_column': self.MAIN_GAIA_TABLE_DEC, 'columns': columns, 'table_name': self.MAIN_GAIA_TABLE or conf.MAIN_GAIA_TABLE, 'ra': ra, 'dec': dec, 'width': widthDeg.value, 'height': heightDeg.value}) @@ -435,7 +439,7 @@ def __query_object(self, coordinate, radius=None, width=None, height=None, return job.get_results() def query_object(self, coordinate, radius=None, width=None, height=None, - verbose=False, columns=[]): + verbose=False, columns=[], row_limit=None): """Launches a job TAP & TAP+ @@ -453,15 +457,21 @@ def query_object(self, coordinate, radius=None, width=None, height=None, flag to display information about the process columns: list, optional, default [] if empty, all columns will be selected + row_limit : int, optional + The maximum number of retrieved rows. Will default to the value + provided by the configuration system if not set explicitly. The + value -1 removes the limit entirely. Returns ------- The job results (astropy.table). """ - return self.__query_object(coordinate, radius, width, height, async_job=False, verbose=verbose, columns=columns) + return self.__query_object(coordinate, radius, width, height, + async_job=False, verbose=verbose, + columns=columns, row_limit=row_limit) def query_object_async(self, coordinate, radius=None, width=None, - height=None, verbose=False, columns=[]): + height=None, verbose=False, columns=[], row_limit=None): """Launches a job (async) TAP & TAP+ @@ -479,12 +489,17 @@ def query_object_async(self, coordinate, radius=None, width=None, flag to display information about the process columns: list, optional, default [] if empty, all columns will be selected + row_limit : int, optional + The maximum number of retrieved rows. Will default to the value + provided by the configuration system if not set explicitly. The + value -1 removes the limit entirely. Returns ------- The job results (astropy.table). """ - return self.__query_object(coordinate, radius, width, height, async_job=True, verbose=verbose, columns=columns) + return self.__query_object(coordinate, radius, width, height, async_job=True, + verbose=verbose, columns=columns, row_limit=row_limit) def __cone_search(self, coordinate, radius, table_name=None, ra_column_name=MAIN_GAIA_TABLE_RA, @@ -493,7 +508,7 @@ def __cone_search(self, coordinate, radius, table_name=None, background=False, output_file=None, output_format="votable", verbose=False, dump_to_file=False, - columns=[]): + columns=[], row_limit=None): """Cone search sorted by distance TAP & TAP+ @@ -526,6 +541,10 @@ def __cone_search(self, coordinate, radius, table_name=None, if True, the results are saved in a file instead of using memory columns: list, optional, default [] if empty, all columns will be selected + row_limit : int, optional + The maximum number of retrieved rows. Will default to the value + provided by the configuration system if not set explicitly. The + value -1 removes the limit entirely. Returns ------- @@ -542,6 +561,7 @@ def __cone_search(self, coordinate, radius, table_name=None, columns = ','.join(map(str, columns)) else: columns = "*" + row_limit = row_limit or self.ROW_LIMIT or conf.ROW_LIMIT query = """ SELECT @@ -561,7 +581,7 @@ def __cone_search(self, coordinate, radius, table_name=None, ORDER BY dist ASC """.format(**{'ra_column': ra_column_name, - 'row_limit': "TOP {0}".format(self.ROW_LIMIT) if self.ROW_LIMIT > 0 else "", + 'row_limit': "TOP {0}".format(row_limit) if row_limit > 0 else "", 'dec_column': dec_column_name, 'columns': columns, 'ra': ra, 'dec': dec, 'radius': radiusDeg, 'table_name': table_name or self.MAIN_GAIA_TABLE or conf.MAIN_GAIA_TABLE}) @@ -586,7 +606,7 @@ def cone_search(self, coordinate, radius=None, output_file=None, output_format="votable", verbose=False, dump_to_file=False, - columns=[]): + columns=[], row_limit=None): """Cone search sorted by distance (sync.) TAP & TAP+ @@ -613,6 +633,10 @@ def cone_search(self, coordinate, radius=None, if True, the results are saved in a file instead of using memory columns: list, optional, default [] if empty, all columns will be selected + row_limit : int, optional + The maximum number of retrieved rows. Will default to the value + provided by the configuration system if not set explicitly. The + value -1 removes the limit entirely. Returns ------- @@ -628,7 +652,7 @@ def cone_search(self, coordinate, radius=None, output_file=output_file, output_format=output_format, verbose=verbose, - dump_to_file=dump_to_file, columns=columns) + dump_to_file=dump_to_file, columns=columns, row_limit=row_limit) def cone_search_async(self, coordinate, radius=None, table_name=None, @@ -636,7 +660,7 @@ def cone_search_async(self, coordinate, radius=None, dec_column_name=MAIN_GAIA_TABLE_DEC, background=False, output_file=None, output_format="votable", - verbose=False, dump_to_file=False, columns=[]): + verbose=False, dump_to_file=False, columns=[], row_limit=None): """Cone search sorted by distance (async) TAP & TAP+ @@ -665,6 +689,10 @@ def cone_search_async(self, coordinate, radius=None, flag to display information about the process dump_to_file : bool, optional, default 'False' if True, the results are saved in a file instead of using memory + row_limit : int, optional + The maximum number of retrieved rows. Will default to the value + provided by the configuration system if not set explicitly. The + value -1 removes the limit entirely. Returns ------- @@ -680,7 +708,7 @@ def cone_search_async(self, coordinate, radius=None, output_file=output_file, output_format=output_format, verbose=verbose, - dump_to_file=dump_to_file, columns=columns) + dump_to_file=dump_to_file, columns=columns, row_limit=row_limit) def __checkQuantityInput(self, value, msg): if not (isinstance(value, str) or isinstance(value, units.Quantity)): diff --git a/astroquery/gaia/tests/test_gaia_remote.py b/astroquery/gaia/tests/test_gaia_remote.py index 98f34f100f..3c919b6316 100644 --- a/astroquery/gaia/tests/test_gaia_remote.py +++ b/astroquery/gaia/tests/test_gaia_remote.py @@ -2,6 +2,7 @@ import pytest from astropy.coordinates import SkyCoord +from astroquery.gaia import conf from .. import GaiaClass @@ -13,15 +14,14 @@ def test_query_object_row_limit(): height = u.Quantity(0.1, u.deg) r = Gaia.query_object_async(coordinate=coord, width=width, height=height) - assert len(r) == Gaia.ROW_LIMIT + assert len(r) == conf.ROW_LIMIT Gaia.ROW_LIMIT = 10 r = Gaia.query_object_async(coordinate=coord, width=width, height=height) assert len(r) == 10 == Gaia.ROW_LIMIT - Gaia.ROW_LIMIT = -1 - r = Gaia.query_object_async(coordinate=coord, width=width, height=height) + r = Gaia.query_object_async(coordinate=coord, width=width, height=height, row_limit=-1) assert len(r) == 176 @@ -34,7 +34,7 @@ def test_cone_search_row_limit(): j = Gaia.cone_search_async(coord, radius) r = j.get_results() - assert len(r) == Gaia.ROW_LIMIT + assert len(r) == conf.ROW_LIMIT Gaia.ROW_LIMIT = 10 j = Gaia.cone_search_async(coord, radius) @@ -42,8 +42,7 @@ def test_cone_search_row_limit(): assert len(r) == 10 == Gaia.ROW_LIMIT - Gaia.ROW_LIMIT = -1 - j = Gaia.cone_search_async(coord, radius) + j = Gaia.cone_search_async(coord, radius, row_limit=-1) r = j.get_results() assert len(r) == 1188 diff --git a/astroquery/gaia/tests/test_gaiatap.py b/astroquery/gaia/tests/test_gaiatap.py index 77abccb2ee..78fd6e1ff0 100644 --- a/astroquery/gaia/tests/test_gaiatap.py +++ b/astroquery/gaia/tests/test_gaiatap.py @@ -360,6 +360,23 @@ def test_cone_search_async(self): # Cleanup. conf.reset('MAIN_GAIA_TABLE') + # Test the default value from conf. + assert 'TOP 50' in job.parameters['query'] + # Test changing the row limit through conf at runtime. + with conf.set_temp('ROW_LIMIT', 42): + job = tap.cone_search_async(sc, radius) + assert 'TOP 42' in job.parameters['query'] + # Changing the value through the class should overrule conf. + tap.ROW_LIMIT = 17 + job = tap.cone_search_async(sc, radius) + assert 'TOP 17' in job.parameters['query'] + # Function argument has highest priority. + job = tap.cone_search_async(sc, radius, row_limit=9) + assert 'TOP 9' in job.parameters['query'] + # No row limit + job = tap.cone_search_async(sc, radius, row_limit=-1) + assert 'TOP' not in job.parameters['query'] + def __check_results_column(self, results, columnName, description, unit, dataType): c = results[columnName] diff --git a/docs/gaia/gaia.rst b/docs/gaia/gaia.rst index 48a81f61e7..632b557030 100644 --- a/docs/gaia/gaia.rst +++ b/docs/gaia/gaia.rst @@ -125,11 +125,16 @@ degrees around an specific point in RA/Dec coordinates. 0.021615117161838747 1635721458409799680 ... Length = 50 rows -Queries return a limited number of rows controlled by ``Gaia.ROW_LIMIT``. To change the default behaviour set this appropriately. +By default the number of rows returned by a query is limited by the +``astroquery.gaia.conf.ROW_LIMIT`` value. This value can be overruled in a +single function call with the ``row_limit`` argument. Alternatively, if the +class attribute ``Gaia.ROW_LIMIT`` is set then it will take precedence over +``conf.ROW_LIMIT``. .. code-block:: python - >>> Gaia.ROW_LIMIT = 8 + >>> from astroquery.gaia import conf + >>> conf.ROW_LIMIT = 8 # Or Gaia.ROW_LIMIT = 8 >>> r = Gaia.query_object_async(coordinate=coord, width=width, height=height) >>> r.pprint() @@ -145,12 +150,12 @@ Queries return a limited number of rows controlled by ``Gaia.ROW_LIMIT``. To cha 0.007469463683838576 1635721458409799680 ... 0.008202004514524316 1635721458409799680 ... -To return an unlimited number of rows set ``Gaia.ROW_LIMIT`` to -1. +To return an unlimited number of rows set the row limit to ``-1``. .. code-block:: python - >>> Gaia.ROW_LIMIT = -1 - >>> r = Gaia.query_object_async(coordinate=coord, width=width, height=height) + >>> r = Gaia.query_object_async(coordinate=coord, width=width, height=height, + ... row_limit=-1) >>> r.pprint() dist solution_id ... epoch_photometry_url @@ -184,7 +189,7 @@ To return an unlimited number of rows set ``Gaia.ROW_LIMIT`` to -1. ~~~~~~~~~~~~~~~~ This query performs a cone search centered at the specified RA/Dec coordinates with the provided -radius argument. +radius argument. The number of rows is limited just like in object queries. .. code-block:: python From bc0129ebd39b11b3b7f96bbbe49eeb1257faa3c9 Mon Sep 17 00:00:00 2001 From: Eero Vaher Date: Tue, 26 Oct 2021 17:54:00 +0200 Subject: [PATCH 2/3] Warn the user if the Gaia result has limited rows The `query_object` and `cone_search` families of functions in the Gaia module now emit a `MaxResultsWarning` if the number of rows in the query result matches the row limit. --- astroquery/gaia/core.py | 30 ++++++++++++++--------- astroquery/gaia/tests/test_gaia_remote.py | 21 +++++++++++++--- astroquery/gaia/tests/test_gaiatap.py | 9 +++++++ docs/gaia/gaia.rst | 6 +++++ 4 files changed, 50 insertions(+), 16 deletions(-) diff --git a/astroquery/gaia/core.py b/astroquery/gaia/core.py index 8b1a6202ce..8f94122ebf 100644 --- a/astroquery/gaia/core.py +++ b/astroquery/gaia/core.py @@ -14,8 +14,11 @@ """ +from warnings import warn + from requests import HTTPError +from astroquery.exceptions import MaxResultsWarning from astroquery.utils.tap import TapPlus from astroquery.utils import commons from astroquery import log @@ -436,7 +439,11 @@ def __query_object(self, coordinate, radius=None, width=None, height=None, job = self.launch_job_async(query, verbose=verbose) else: job = self.launch_job(query, verbose=verbose) - return job.get_results() + table = job.get_results() + if len(table) == row_limit: + warn(f'The number of rows in the result matches the current row limit of {row_limit}. ' + f'You might wish to specify a different "row_limit" value.', MaxResultsWarning) + return table def query_object(self, coordinate, radius=None, width=None, height=None, verbose=False, columns=[], row_limit=None): @@ -586,18 +593,17 @@ def __cone_search(self, coordinate, radius, table_name=None, 'radius': radiusDeg, 'table_name': table_name or self.MAIN_GAIA_TABLE or conf.MAIN_GAIA_TABLE}) if async_job: - return self.launch_job_async(query=query, - output_file=output_file, - output_format=output_format, - verbose=verbose, - dump_to_file=dump_to_file, - background=background) + result = self.launch_job_async(query=query, output_file=output_file, + output_format=output_format, verbose=verbose, + dump_to_file=dump_to_file, background=background) else: - return self.launch_job(query=query, - output_file=output_file, - output_format=output_format, - verbose=verbose, - dump_to_file=dump_to_file) + result = self.launch_job(query=query, output_file=output_file, + output_format=output_format, verbose=verbose, + dump_to_file=dump_to_file) + if len(result.get_data()) == row_limit: + warn(f'The number of rows in the result matches the current row limit of {row_limit}. ' + f'You might wish to specify a different "row_limit" value.', MaxResultsWarning) + return result def cone_search(self, coordinate, radius=None, table_name=None, diff --git a/astroquery/gaia/tests/test_gaia_remote.py b/astroquery/gaia/tests/test_gaia_remote.py index 3c919b6316..9b2c8cba42 100644 --- a/astroquery/gaia/tests/test_gaia_remote.py +++ b/astroquery/gaia/tests/test_gaia_remote.py @@ -2,6 +2,7 @@ import pytest from astropy.coordinates import SkyCoord +from astroquery.exceptions import MaxResultsWarning from astroquery.gaia import conf from .. import GaiaClass @@ -12,12 +13,18 @@ def test_query_object_row_limit(): coord = SkyCoord(ra=280, dec=-60, unit=(u.degree, u.degree), frame='icrs') width = u.Quantity(0.1, u.deg) height = u.Quantity(0.1, u.deg) - r = Gaia.query_object_async(coordinate=coord, width=width, height=height) + msg = ('The number of rows in the result matches the current row limit of 50. You might wish ' + 'to specify a different "row_limit" value.') + with pytest.warns(MaxResultsWarning, match=msg): + r = Gaia.query_object_async(coordinate=coord, width=width, height=height) assert len(r) == conf.ROW_LIMIT Gaia.ROW_LIMIT = 10 - r = Gaia.query_object_async(coordinate=coord, width=width, height=height) + msg = ('The number of rows in the result matches the current row limit of ' + '10. You might wish to specify a different "row_limit" value.') + with pytest.warns(MaxResultsWarning, match=msg): + r = Gaia.query_object_async(coordinate=coord, width=width, height=height) assert len(r) == 10 == Gaia.ROW_LIMIT @@ -31,13 +38,19 @@ def test_cone_search_row_limit(): Gaia = GaiaClass() coord = SkyCoord(ra=280, dec=-60, unit=(u.degree, u.degree), frame='icrs') radius = u.Quantity(0.1, u.deg) - j = Gaia.cone_search_async(coord, radius) + msg = ('The number of rows in the result matches the current row limit of 50. You might wish ' + 'to specify a different "row_limit" value.') + with pytest.warns(MaxResultsWarning, match=msg): + j = Gaia.cone_search_async(coord, radius) r = j.get_results() assert len(r) == conf.ROW_LIMIT Gaia.ROW_LIMIT = 10 - j = Gaia.cone_search_async(coord, radius) + msg = ('The number of rows in the result matches the current row limit of 10. You might wish ' + 'to specify a different "row_limit" value.') + with pytest.warns(MaxResultsWarning, match=msg): + j = Gaia.cone_search_async(coord, radius) r = j.get_results() assert len(r) == 10 == Gaia.ROW_LIMIT diff --git a/astroquery/gaia/tests/test_gaiatap.py b/astroquery/gaia/tests/test_gaiatap.py index 78fd6e1ff0..8bdfef944b 100644 --- a/astroquery/gaia/tests/test_gaiatap.py +++ b/astroquery/gaia/tests/test_gaiatap.py @@ -18,6 +18,7 @@ import os import pytest +from astroquery.exceptions import MaxResultsWarning from astroquery.gaia import conf from astroquery.gaia.core import GaiaClass from astroquery.gaia.tests.DummyTapHandler import DummyTapHandler @@ -214,6 +215,10 @@ def test_query_object_async(self): 'table1_oid', None, np.int32) + msg = ('The number of rows in the result matches the current row limit of 3. You might ' + 'wish to specify a different "row_limit" value.') + with pytest.warns(MaxResultsWarning, match=msg): + job = tap.query_object_async(sc, radius, row_limit=3) def test_cone_search_sync(self): connHandler = DummyConnHandler() @@ -376,6 +381,10 @@ def test_cone_search_async(self): # No row limit job = tap.cone_search_async(sc, radius, row_limit=-1) assert 'TOP' not in job.parameters['query'] + msg = ('The number of rows in the result matches the current row limit of 3. You might ' + 'wish to specify a different "row_limit" value.') + with pytest.warns(MaxResultsWarning, match=msg): + job = tap.cone_search_async(sc, radius, row_limit=3) def __check_results_column(self, results, columnName, description, unit, dataType): diff --git a/docs/gaia/gaia.rst b/docs/gaia/gaia.rst index 632b557030..e111872739 100644 --- a/docs/gaia/gaia.rst +++ b/docs/gaia/gaia.rst @@ -124,6 +124,8 @@ degrees around an specific point in RA/Dec coordinates. 0.020802655215768254 1635721458409799680 ... 0.021615117161838747 1635721458409799680 ... Length = 50 rows + MaxResultsWarning: The number of rows in the result matches the current row + limit of 50. You might wish to specify a different "row_limit" value. By default the number of rows returned by a query is limited by the ``astroquery.gaia.conf.ROW_LIMIT`` value. This value can be overruled in a @@ -149,6 +151,8 @@ class attribute ``Gaia.ROW_LIMIT`` is set then it will take precedence over 0.006209042666371929 1635721458409799680 ... 0.007469463683838576 1635721458409799680 ... 0.008202004514524316 1635721458409799680 ... + MaxResultsWarning: The number of rows in the result matches the current row + limit of 8. You might wish to specify a different "row_limit" value. To return an unlimited number of rows set the row limit to ``-1``. @@ -213,6 +217,8 @@ radius argument. The number of rows is limited just like in object queries. 1635721458409799680 Gaia DR2 6636090334814218752 ... 0.005846434715822121 ... ... ... ... Length = 50 rows + MaxResultsWarning: The number of rows in the result matches the current row + limit of 50. You might wish to specify a different "row_limit" value. 1.3. Getting public tables metadata From a2f0ee9c6c47bfe88e4f1b03cdb40a79ef84eddd Mon Sep 17 00:00:00 2001 From: Eero Vaher Date: Fri, 29 Oct 2021 18:13:49 +0200 Subject: [PATCH 3/3] Restrict `gaia` row limit warnings to verbose=True The `query_object` and `cone_search` families of functions in `astroquery.gaia` no longer emit a `MaxResultsWarning` unless they were called with `verbose=True`. --- astroquery/gaia/core.py | 4 ++-- astroquery/gaia/tests/test_gaia_remote.py | 14 ++++---------- astroquery/gaia/tests/test_gaiatap.py | 8 ++++++-- docs/gaia/gaia.rst | 10 ++++------ 4 files changed, 16 insertions(+), 20 deletions(-) diff --git a/astroquery/gaia/core.py b/astroquery/gaia/core.py index 8f94122ebf..d8f373fcc8 100644 --- a/astroquery/gaia/core.py +++ b/astroquery/gaia/core.py @@ -440,7 +440,7 @@ def __query_object(self, coordinate, radius=None, width=None, height=None, else: job = self.launch_job(query, verbose=verbose) table = job.get_results() - if len(table) == row_limit: + if verbose and len(table) == row_limit: warn(f'The number of rows in the result matches the current row limit of {row_limit}. ' f'You might wish to specify a different "row_limit" value.', MaxResultsWarning) return table @@ -600,7 +600,7 @@ def __cone_search(self, coordinate, radius, table_name=None, result = self.launch_job(query=query, output_file=output_file, output_format=output_format, verbose=verbose, dump_to_file=dump_to_file) - if len(result.get_data()) == row_limit: + if verbose and len(result.get_data()) == row_limit: warn(f'The number of rows in the result matches the current row limit of {row_limit}. ' f'You might wish to specify a different "row_limit" value.', MaxResultsWarning) return result diff --git a/astroquery/gaia/tests/test_gaia_remote.py b/astroquery/gaia/tests/test_gaia_remote.py index 9b2c8cba42..aa3ad4f0d4 100644 --- a/astroquery/gaia/tests/test_gaia_remote.py +++ b/astroquery/gaia/tests/test_gaia_remote.py @@ -13,10 +13,7 @@ def test_query_object_row_limit(): coord = SkyCoord(ra=280, dec=-60, unit=(u.degree, u.degree), frame='icrs') width = u.Quantity(0.1, u.deg) height = u.Quantity(0.1, u.deg) - msg = ('The number of rows in the result matches the current row limit of 50. You might wish ' - 'to specify a different "row_limit" value.') - with pytest.warns(MaxResultsWarning, match=msg): - r = Gaia.query_object_async(coordinate=coord, width=width, height=height) + r = Gaia.query_object_async(coordinate=coord, width=width, height=height) assert len(r) == conf.ROW_LIMIT @@ -24,7 +21,7 @@ def test_query_object_row_limit(): msg = ('The number of rows in the result matches the current row limit of ' '10. You might wish to specify a different "row_limit" value.') with pytest.warns(MaxResultsWarning, match=msg): - r = Gaia.query_object_async(coordinate=coord, width=width, height=height) + r = Gaia.query_object_async(coordinate=coord, width=width, height=height, verbose=True) assert len(r) == 10 == Gaia.ROW_LIMIT @@ -38,10 +35,7 @@ def test_cone_search_row_limit(): Gaia = GaiaClass() coord = SkyCoord(ra=280, dec=-60, unit=(u.degree, u.degree), frame='icrs') radius = u.Quantity(0.1, u.deg) - msg = ('The number of rows in the result matches the current row limit of 50. You might wish ' - 'to specify a different "row_limit" value.') - with pytest.warns(MaxResultsWarning, match=msg): - j = Gaia.cone_search_async(coord, radius) + j = Gaia.cone_search_async(coord, radius) r = j.get_results() assert len(r) == conf.ROW_LIMIT @@ -50,7 +44,7 @@ def test_cone_search_row_limit(): msg = ('The number of rows in the result matches the current row limit of 10. You might wish ' 'to specify a different "row_limit" value.') with pytest.warns(MaxResultsWarning, match=msg): - j = Gaia.cone_search_async(coord, radius) + j = Gaia.cone_search_async(coord, radius, verbose=True) r = j.get_results() assert len(r) == 10 == Gaia.ROW_LIMIT diff --git a/astroquery/gaia/tests/test_gaiatap.py b/astroquery/gaia/tests/test_gaiatap.py index 8bdfef944b..a6080e2488 100644 --- a/astroquery/gaia/tests/test_gaiatap.py +++ b/astroquery/gaia/tests/test_gaiatap.py @@ -215,10 +215,12 @@ def test_query_object_async(self): 'table1_oid', None, np.int32) + # No warning without verbose=True + job = tap.query_object_async(sc, radius, row_limit=3) msg = ('The number of rows in the result matches the current row limit of 3. You might ' 'wish to specify a different "row_limit" value.') with pytest.warns(MaxResultsWarning, match=msg): - job = tap.query_object_async(sc, radius, row_limit=3) + job = tap.query_object_async(sc, radius, row_limit=3, verbose=True) def test_cone_search_sync(self): connHandler = DummyConnHandler() @@ -381,10 +383,12 @@ def test_cone_search_async(self): # No row limit job = tap.cone_search_async(sc, radius, row_limit=-1) assert 'TOP' not in job.parameters['query'] + # No warning without verbose=True + job = tap.cone_search_async(sc, radius, row_limit=3) msg = ('The number of rows in the result matches the current row limit of 3. You might ' 'wish to specify a different "row_limit" value.') with pytest.warns(MaxResultsWarning, match=msg): - job = tap.cone_search_async(sc, radius, row_limit=3) + job = tap.cone_search_async(sc, radius, row_limit=3, verbose=True) def __check_results_column(self, results, columnName, description, unit, dataType): diff --git a/docs/gaia/gaia.rst b/docs/gaia/gaia.rst index e111872739..6690adc504 100644 --- a/docs/gaia/gaia.rst +++ b/docs/gaia/gaia.rst @@ -124,20 +124,20 @@ degrees around an specific point in RA/Dec coordinates. 0.020802655215768254 1635721458409799680 ... 0.021615117161838747 1635721458409799680 ... Length = 50 rows - MaxResultsWarning: The number of rows in the result matches the current row - limit of 50. You might wish to specify a different "row_limit" value. By default the number of rows returned by a query is limited by the ``astroquery.gaia.conf.ROW_LIMIT`` value. This value can be overruled in a single function call with the ``row_limit`` argument. Alternatively, if the class attribute ``Gaia.ROW_LIMIT`` is set then it will take precedence over -``conf.ROW_LIMIT``. +``conf.ROW_LIMIT``. If you call the function with ``verbose=True`` then you +will be warned if the length of the query result is equal to the row limit. .. code-block:: python >>> from astroquery.gaia import conf >>> conf.ROW_LIMIT = 8 # Or Gaia.ROW_LIMIT = 8 - >>> r = Gaia.query_object_async(coordinate=coord, width=width, height=height) + >>> r = Gaia.query_object_async(coordinate=coord, width=width, height=height, + verbose=True) >>> r.pprint() dist solution_id ... epoch_photometry_url @@ -217,8 +217,6 @@ radius argument. The number of rows is limited just like in object queries. 1635721458409799680 Gaia DR2 6636090334814218752 ... 0.005846434715822121 ... ... ... ... Length = 50 rows - MaxResultsWarning: The number of rows in the result matches the current row - limit of 50. You might wish to specify a different "row_limit" value. 1.3. Getting public tables metadata