Skip to content

Commit bc0129e

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

File tree

4 files changed

+50
-16
lines changed

4 files changed

+50
-16
lines changed

astroquery/gaia/core.py

+18-12
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@
1414
1515
1616
"""
17+
from warnings import warn
18+
1719
from requests import HTTPError
1820

21+
from astroquery.exceptions import MaxResultsWarning
1922
from astroquery.utils.tap import TapPlus
2023
from astroquery.utils import commons
2124
from astroquery import log
@@ -436,7 +439,11 @@ def __query_object(self, coordinate, radius=None, width=None, height=None,
436439
job = self.launch_job_async(query, verbose=verbose)
437440
else:
438441
job = self.launch_job(query, verbose=verbose)
439-
return job.get_results()
442+
table = job.get_results()
443+
if len(table) == row_limit:
444+
warn(f'The number of rows in the result matches the current row limit of {row_limit}. '
445+
f'You might wish to specify a different "row_limit" value.', MaxResultsWarning)
446+
return table
440447

441448
def query_object(self, coordinate, radius=None, width=None, height=None,
442449
verbose=False, columns=[], row_limit=None):
@@ -586,18 +593,17 @@ def __cone_search(self, coordinate, radius, table_name=None,
586593
'radius': radiusDeg, 'table_name': table_name or self.MAIN_GAIA_TABLE or conf.MAIN_GAIA_TABLE})
587594

588595
if async_job:
589-
return self.launch_job_async(query=query,
590-
output_file=output_file,
591-
output_format=output_format,
592-
verbose=verbose,
593-
dump_to_file=dump_to_file,
594-
background=background)
596+
result = self.launch_job_async(query=query, output_file=output_file,
597+
output_format=output_format, verbose=verbose,
598+
dump_to_file=dump_to_file, background=background)
595599
else:
596-
return self.launch_job(query=query,
597-
output_file=output_file,
598-
output_format=output_format,
599-
verbose=verbose,
600-
dump_to_file=dump_to_file)
600+
result = self.launch_job(query=query, output_file=output_file,
601+
output_format=output_format, verbose=verbose,
602+
dump_to_file=dump_to_file)
603+
if len(result.get_data()) == row_limit:
604+
warn(f'The number of rows in the result matches the current row limit of {row_limit}. '
605+
f'You might wish to specify a different "row_limit" value.', MaxResultsWarning)
606+
return result
601607

602608
def cone_search(self, coordinate, radius=None,
603609
table_name=None,

astroquery/gaia/tests/test_gaia_remote.py

+17-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import pytest
33
from astropy.coordinates import SkyCoord
44

5+
from astroquery.exceptions import MaxResultsWarning
56
from astroquery.gaia import conf
67
from .. import GaiaClass
78

@@ -12,12 +13,18 @@ def test_query_object_row_limit():
1213
coord = SkyCoord(ra=280, dec=-60, unit=(u.degree, u.degree), frame='icrs')
1314
width = u.Quantity(0.1, u.deg)
1415
height = u.Quantity(0.1, u.deg)
15-
r = Gaia.query_object_async(coordinate=coord, width=width, height=height)
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)
1620

1721
assert len(r) == conf.ROW_LIMIT
1822

1923
Gaia.ROW_LIMIT = 10
20-
r = Gaia.query_object_async(coordinate=coord, width=width, height=height)
24+
msg = ('The number of rows in the result matches the current row limit of '
25+
'10. You might wish to specify a different "row_limit" value.')
26+
with pytest.warns(MaxResultsWarning, match=msg):
27+
r = Gaia.query_object_async(coordinate=coord, width=width, height=height)
2128

2229
assert len(r) == 10 == Gaia.ROW_LIMIT
2330

@@ -31,13 +38,19 @@ def test_cone_search_row_limit():
3138
Gaia = GaiaClass()
3239
coord = SkyCoord(ra=280, dec=-60, unit=(u.degree, u.degree), frame='icrs')
3340
radius = u.Quantity(0.1, u.deg)
34-
j = Gaia.cone_search_async(coord, radius)
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)
3545
r = j.get_results()
3646

3747
assert len(r) == conf.ROW_LIMIT
3848

3949
Gaia.ROW_LIMIT = 10
40-
j = Gaia.cone_search_async(coord, radius)
50+
msg = ('The number of rows in the result matches the current row limit of 10. You might wish '
51+
'to specify a different "row_limit" value.')
52+
with pytest.warns(MaxResultsWarning, match=msg):
53+
j = Gaia.cone_search_async(coord, radius)
4154
r = j.get_results()
4255

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

astroquery/gaia/tests/test_gaiatap.py

+9
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import os
1919
import pytest
2020

21+
from astroquery.exceptions import MaxResultsWarning
2122
from astroquery.gaia import conf
2223
from astroquery.gaia.core import GaiaClass
2324
from astroquery.gaia.tests.DummyTapHandler import DummyTapHandler
@@ -214,6 +215,10 @@ def test_query_object_async(self):
214215
'table1_oid',
215216
None,
216217
np.int32)
218+
msg = ('The number of rows in the result matches the current row limit of 3. You might '
219+
'wish to specify a different "row_limit" value.')
220+
with pytest.warns(MaxResultsWarning, match=msg):
221+
job = tap.query_object_async(sc, radius, row_limit=3)
217222

218223
def test_cone_search_sync(self):
219224
connHandler = DummyConnHandler()
@@ -376,6 +381,10 @@ def test_cone_search_async(self):
376381
# No row limit
377382
job = tap.cone_search_async(sc, radius, row_limit=-1)
378383
assert 'TOP' not in job.parameters['query']
384+
msg = ('The number of rows in the result matches the current row limit of 3. You might '
385+
'wish to specify a different "row_limit" value.')
386+
with pytest.warns(MaxResultsWarning, match=msg):
387+
job = tap.cone_search_async(sc, radius, row_limit=3)
379388

380389
def __check_results_column(self, results, columnName, description, unit,
381390
dataType):

docs/gaia/gaia.rst

+6
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ 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.
127129
128130
By default the number of rows returned by a query is limited by the
129131
``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
149151
0.006209042666371929 1635721458409799680 ...
150152
0.007469463683838576 1635721458409799680 ...
151153
0.008202004514524316 1635721458409799680 ...
154+
MaxResultsWarning: The number of rows in the result matches the current row
155+
limit of 8. You might wish to specify a different "row_limit" value.
152156
153157
To return an unlimited number of rows set the row limit to ``-1``.
154158

@@ -213,6 +217,8 @@ radius argument. The number of rows is limited just like in object queries.
213217
1635721458409799680 Gaia DR2 6636090334814218752 ... 0.005846434715822121
214218
... ... ... ...
215219
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.
216222
217223
218224
1.3. Getting public tables metadata

0 commit comments

Comments
 (0)