Skip to content

Commit 98ecac4

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 `UserWarning` if the number of rows in the query result matches the row limit.
1 parent 7e0b359 commit 98ecac4

File tree

4 files changed

+57
-17
lines changed

4 files changed

+57
-17
lines changed

astroquery/gaia/core.py

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

1921
from astroquery.utils.tap import TapPlus
@@ -437,7 +439,12 @@ def __query_object(self, coordinate, radius=None, width=None, height=None,
437439
job = self.launch_job_async(query, verbose=verbose)
438440
else:
439441
job = self.launch_job(query, verbose=verbose)
440-
return job.get_results()
442+
table = job.get_results()
443+
if len(table) == row_limit:
444+
warn('The number of rows in the result matches the current row '
445+
f'limit of {row_limit}. You might wish to specify a '
446+
f'different "row_limit" value.', UserWarning)
447+
return table
441448

442449
def query_object(self, coordinate, radius=None, width=None, height=None,
443450
verbose=False, columns=[], row_limit=None):
@@ -589,18 +596,22 @@ def __cone_search(self, coordinate, radius, table_name=None,
589596
'radius': radiusDeg, 'table_name': table_name or self.MAIN_GAIA_TABLE or conf.MAIN_GAIA_TABLE})
590597

591598
if async_job:
592-
return self.launch_job_async(query=query,
593-
output_file=output_file,
594-
output_format=output_format,
595-
verbose=verbose,
596-
dump_to_file=dump_to_file,
597-
background=background)
599+
result = self.launch_job_async(query=query,
600+
output_file=output_file,
601+
output_format=output_format,
602+
verbose=verbose,
603+
dump_to_file=dump_to_file,
604+
background=background)
598605
else:
599-
return self.launch_job(query=query,
600-
output_file=output_file,
601-
output_format=output_format,
602-
verbose=verbose,
603-
dump_to_file=dump_to_file)
606+
result = self.launch_job(query=query, output_file=output_file,
607+
output_format=output_format,
608+
verbose=verbose,
609+
dump_to_file=dump_to_file)
610+
if len(result.get_data()) == row_limit:
611+
warn('The number of rows in the result matches the current row '
612+
f'limit of {row_limit}. You might wish to specify a '
613+
f'different "row_limit" value.', UserWarning)
614+
return result
604615

605616
def cone_search(self, coordinate, radius=None,
606617
table_name=None,

astroquery/gaia/tests/test_gaia_remote.py

+18-4
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,20 @@ def test_query_object_row_limit():
1212
coord = SkyCoord(ra=280, dec=-60, unit=(u.degree, u.degree), frame='icrs')
1313
width = u.Quantity(0.1, u.deg)
1414
height = u.Quantity(0.1, u.deg)
15-
r = Gaia.query_object_async(coordinate=coord, width=width, height=height)
15+
msg = ('The number of rows in the result matches the current row limit of '
16+
'50. You might wish to specify a different "row_limit" value.')
17+
with pytest.warns(UserWarning, match=msg):
18+
r = Gaia.query_object_async(coordinate=coord, width=width,
19+
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(UserWarning, match=msg):
27+
r = Gaia.query_object_async(coordinate=coord, width=width,
28+
height=height)
2129

2230
assert len(r) == 10 == Gaia.ROW_LIMIT
2331

@@ -32,13 +40,19 @@ def test_cone_search_row_limit():
3240
Gaia = GaiaClass()
3341
coord = SkyCoord(ra=280, dec=-60, unit=(u.degree, u.degree), frame='icrs')
3442
radius = u.Quantity(0.1, u.deg)
35-
j = Gaia.cone_search_async(coord, radius)
43+
msg = ('The number of rows in the result matches the current row limit of '
44+
'50. You might wish to specify a different "row_limit" value.')
45+
with pytest.warns(UserWarning, match=msg):
46+
j = Gaia.cone_search_async(coord, radius)
3647
r = j.get_results()
3748

3849
assert len(r) == conf.ROW_LIMIT
3950

4051
Gaia.ROW_LIMIT = 10
41-
j = Gaia.cone_search_async(coord, radius)
52+
msg = ('The number of rows in the result matches the current row limit of '
53+
'10. You might wish to specify a different "row_limit" value.')
54+
with pytest.warns(UserWarning, match=msg):
55+
j = Gaia.cone_search_async(coord, radius)
4256
r = j.get_results()
4357

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

astroquery/gaia/tests/test_gaiatap.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,11 @@ def test_query_object_async(self):
214214
'table1_oid',
215215
None,
216216
np.int32)
217+
msg = ('The number of rows in the result matches the current row '
218+
'limit of 3. You might wish to specify a different "row_limit" '
219+
'value.')
220+
with pytest.warns(UserWarning, 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,7 +381,11 @@ 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']
379-
384+
msg = ('The number of rows in the result matches the current row '
385+
'limit of 3. You might wish to specify a different "row_limit" '
386+
'value.')
387+
with pytest.warns(UserWarning, match=msg):
388+
job = tap.cone_search_async(sc, radius, row_limit=3)
380389

381390
def __check_results_column(self, results, columnName, description, unit,
382391
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+
UserWarning: The number of rows in the result matches the current row limit
128+
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+
UserWarning: The number of rows in the result matches the current row limit
155+
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+
UserWarning: The number of rows in the result matches the current row limit
221+
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)