Skip to content

Commit a2f0ee9

Browse files
committed
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`.
1 parent bc0129e commit a2f0ee9

File tree

4 files changed

+16
-20
lines changed

4 files changed

+16
-20
lines changed

astroquery/gaia/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ def __query_object(self, coordinate, radius=None, width=None, height=None,
440440
else:
441441
job = self.launch_job(query, verbose=verbose)
442442
table = job.get_results()
443-
if len(table) == row_limit:
443+
if verbose and len(table) == row_limit:
444444
warn(f'The number of rows in the result matches the current row limit of {row_limit}. '
445445
f'You might wish to specify a different "row_limit" value.', MaxResultsWarning)
446446
return table
@@ -600,7 +600,7 @@ def __cone_search(self, coordinate, radius, table_name=None,
600600
result = self.launch_job(query=query, output_file=output_file,
601601
output_format=output_format, verbose=verbose,
602602
dump_to_file=dump_to_file)
603-
if len(result.get_data()) == row_limit:
603+
if verbose and len(result.get_data()) == row_limit:
604604
warn(f'The number of rows in the result matches the current row limit of {row_limit}. '
605605
f'You might wish to specify a different "row_limit" value.', MaxResultsWarning)
606606
return result

astroquery/gaia/tests/test_gaia_remote.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,15 @@ def test_query_object_row_limit():
1313
coord = SkyCoord(ra=280, dec=-60, unit=(u.degree, u.degree), frame='icrs')
1414
width = u.Quantity(0.1, u.deg)
1515
height = u.Quantity(0.1, u.deg)
16-
msg = ('The number of rows in the result matches the current row limit of 50. You might wish '
17-
'to specify a different "row_limit" value.')
18-
with pytest.warns(MaxResultsWarning, match=msg):
19-
r = Gaia.query_object_async(coordinate=coord, width=width, height=height)
16+
r = Gaia.query_object_async(coordinate=coord, width=width, height=height)
2017

2118
assert len(r) == conf.ROW_LIMIT
2219

2320
Gaia.ROW_LIMIT = 10
2421
msg = ('The number of rows in the result matches the current row limit of '
2522
'10. You might wish to specify a different "row_limit" value.')
2623
with pytest.warns(MaxResultsWarning, match=msg):
27-
r = Gaia.query_object_async(coordinate=coord, width=width, height=height)
24+
r = Gaia.query_object_async(coordinate=coord, width=width, height=height, verbose=True)
2825

2926
assert len(r) == 10 == Gaia.ROW_LIMIT
3027

@@ -38,10 +35,7 @@ def test_cone_search_row_limit():
3835
Gaia = GaiaClass()
3936
coord = SkyCoord(ra=280, dec=-60, unit=(u.degree, u.degree), frame='icrs')
4037
radius = u.Quantity(0.1, u.deg)
41-
msg = ('The number of rows in the result matches the current row limit of 50. You might wish '
42-
'to specify a different "row_limit" value.')
43-
with pytest.warns(MaxResultsWarning, match=msg):
44-
j = Gaia.cone_search_async(coord, radius)
38+
j = Gaia.cone_search_async(coord, radius)
4539
r = j.get_results()
4640

4741
assert len(r) == conf.ROW_LIMIT
@@ -50,7 +44,7 @@ def test_cone_search_row_limit():
5044
msg = ('The number of rows in the result matches the current row limit of 10. You might wish '
5145
'to specify a different "row_limit" value.')
5246
with pytest.warns(MaxResultsWarning, match=msg):
53-
j = Gaia.cone_search_async(coord, radius)
47+
j = Gaia.cone_search_async(coord, radius, verbose=True)
5448
r = j.get_results()
5549

5650
assert len(r) == 10 == Gaia.ROW_LIMIT

astroquery/gaia/tests/test_gaiatap.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,12 @@ def test_query_object_async(self):
215215
'table1_oid',
216216
None,
217217
np.int32)
218+
# No warning without verbose=True
219+
job = tap.query_object_async(sc, radius, row_limit=3)
218220
msg = ('The number of rows in the result matches the current row limit of 3. You might '
219221
'wish to specify a different "row_limit" value.')
220222
with pytest.warns(MaxResultsWarning, match=msg):
221-
job = tap.query_object_async(sc, radius, row_limit=3)
223+
job = tap.query_object_async(sc, radius, row_limit=3, verbose=True)
222224

223225
def test_cone_search_sync(self):
224226
connHandler = DummyConnHandler()
@@ -381,10 +383,12 @@ def test_cone_search_async(self):
381383
# No row limit
382384
job = tap.cone_search_async(sc, radius, row_limit=-1)
383385
assert 'TOP' not in job.parameters['query']
386+
# No warning without verbose=True
387+
job = tap.cone_search_async(sc, radius, row_limit=3)
384388
msg = ('The number of rows in the result matches the current row limit of 3. You might '
385389
'wish to specify a different "row_limit" value.')
386390
with pytest.warns(MaxResultsWarning, match=msg):
387-
job = tap.cone_search_async(sc, radius, row_limit=3)
391+
job = tap.cone_search_async(sc, radius, row_limit=3, verbose=True)
388392

389393
def __check_results_column(self, results, columnName, description, unit,
390394
dataType):

docs/gaia/gaia.rst

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,20 +124,20 @@ degrees around an specific point in RA/Dec coordinates.
124124
0.020802655215768254 1635721458409799680 ...
125125
0.021615117161838747 1635721458409799680 ...
126126
Length = 50 rows
127-
MaxResultsWarning: The number of rows in the result matches the current row
128-
limit of 50. You might wish to specify a different "row_limit" value.
129127
130128
By default the number of rows returned by a query is limited by the
131129
``astroquery.gaia.conf.ROW_LIMIT`` value. This value can be overruled in a
132130
single function call with the ``row_limit`` argument. Alternatively, if the
133131
class attribute ``Gaia.ROW_LIMIT`` is set then it will take precedence over
134-
``conf.ROW_LIMIT``.
132+
``conf.ROW_LIMIT``. If you call the function with ``verbose=True`` then you
133+
will be warned if the length of the query result is equal to the row limit.
135134

136135
.. code-block:: python
137136
138137
>>> from astroquery.gaia import conf
139138
>>> conf.ROW_LIMIT = 8 # Or Gaia.ROW_LIMIT = 8
140-
>>> r = Gaia.query_object_async(coordinate=coord, width=width, height=height)
139+
>>> r = Gaia.query_object_async(coordinate=coord, width=width, height=height,
140+
verbose=True)
141141
>>> r.pprint()
142142
143143
dist solution_id ... epoch_photometry_url
@@ -217,8 +217,6 @@ radius argument. The number of rows is limited just like in object queries.
217217
1635721458409799680 Gaia DR2 6636090334814218752 ... 0.005846434715822121
218218
... ... ... ...
219219
Length = 50 rows
220-
MaxResultsWarning: The number of rows in the result matches the current row
221-
limit of 50. You might wish to specify a different "row_limit" value.
222220
223221
224222
1.3. Getting public tables metadata

0 commit comments

Comments
 (0)