Skip to content

Commit 4dbc87c

Browse files
committed
Bugfix - int overflow on maxrec calculation
1 parent bb15ee7 commit 4dbc87c

File tree

2 files changed

+36
-19
lines changed

2 files changed

+36
-19
lines changed

astroquery/eso/core.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -223,22 +223,15 @@ def _get_auth_header(self) -> Dict[str, str]:
223223
else:
224224
return {}
225225

226-
def _maybe_warn_about_table_length(self, table_rowlim_plus_one):
226+
def _maybe_warn_about_table_length(self, table_rowlim_plus_one, row_limit_plus_one):
227227
"""
228228
Issues a warning when a table is empty or when the
229229
results are truncated
230230
"""
231231
if len(table_rowlim_plus_one) < 1:
232232
warnings.warn("Query returned no results", NoResultsWarning)
233233

234-
# Just adding this case for clarification:
235-
if len(table_rowlim_plus_one) == self.ROW_LIMIT:
236-
# We asked for a table with ROW_LIMIT + 1 rows, and got a table with ROW_LIMIT rows.
237-
# This means the table was not truncated, ROW_LIMIT coincides with the table length.
238-
pass
239-
240-
if len(table_rowlim_plus_one) == 1 + self.ROW_LIMIT:
241-
# The table has more than ROW_LIMIT rows, which means it will be artificially truncated.
234+
if len(table_rowlim_plus_one) == row_limit_plus_one:
242235
warnings.warn(f"Results truncated to {self.ROW_LIMIT}. "
243236
"To retrieve all the records set to None the ROW_LIMIT attribute",
244237
MaxResultsWarning)
@@ -256,8 +249,12 @@ def message(query_str):
256249
f' >>> Eso().query_tap( "{query_str}" )\n\n')
257250

258251
try:
259-
table_with_an_extra_row = tap.search(query=query_str, maxrec=self.ROW_LIMIT+1).to_table()
260-
self._maybe_warn_about_table_length(table_with_an_extra_row)
252+
row_limit_plus_one = self.ROW_LIMIT
253+
if self.ROW_LIMIT < sys.maxsize:
254+
row_limit_plus_one = self.ROW_LIMIT + 1
255+
256+
table_with_an_extra_row = tap.search(query=query_str, maxrec=row_limit_plus_one).to_table()
257+
self._maybe_warn_about_table_length(table_with_an_extra_row, row_limit_plus_one)
261258
except DALQueryError:
262259
log.error(message(query_str))
263260
except DALFormatError as e:

astroquery/eso/tests/test_eso_remote.py

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,23 @@
3535
'HAWKI',
3636
'KMOS',
3737
'MW-BULGE-PSFPHOT',
38+
'SEDIGISM',
3839
'VPHASplus',
3940
'VVV',
4041
'VVVX',
4142
'XSHOOTER'
4243
]
4344

45+
ONE_RECORD_SURVEYS = [
46+
'081.C-0827',
47+
'108.2289',
48+
'1100.A-0528',
49+
'60.A-9493',
50+
'APEX-SciOps',
51+
'HARPS',
52+
'LESS',
53+
]
54+
4455

4556
@pytest.mark.remote_data
4657
class TestEso:
@@ -275,14 +286,20 @@ def test_each_survey_sgrastar(self, tmp_path):
275286

276287
surveys = eso.list_surveys()
277288
for survey in surveys:
278-
if survey in SGRA_SURVEYS:
279-
with pytest.warns(MaxResultsWarning):
289+
if survey in SGRA_SURVEYS: # survey contains SGRA
290+
if survey not in ONE_RECORD_SURVEYS: # Expect warnings
291+
with pytest.warns(MaxResultsWarning):
292+
result_s = eso.query_surveys(
293+
surveys=survey,
294+
cone_ra=266.41681662, cone_dec=-29.00782497, cone_radius=0.1775)
295+
else: # No warnings expected
280296
result_s = eso.query_surveys(
281297
surveys=survey,
282298
cone_ra=266.41681662, cone_dec=-29.00782497, cone_radius=0.1775)
299+
283300
assert isinstance(result_s, Table)
284301
assert len(result_s) > 0
285-
else:
302+
else: # survey does not contain SGRA
286303
with pytest.warns(NoResultsWarning):
287304
result_s = eso.query_surveys(surveys=survey, cone_ra=266.41681662,
288305
cone_dec=-29.00782497,
@@ -291,12 +308,15 @@ def test_each_survey_sgrastar(self, tmp_path):
291308
assert isinstance(result_s, Table)
292309
assert len(result_s) == 0, f"Failed for survey {survey}"
293310

294-
with pytest.warns(MaxResultsWarning):
295-
generic_result = eso.query_surveys(surveys=survey)
311+
if survey not in ONE_RECORD_SURVEYS: # Expect warnings
312+
with pytest.warns(MaxResultsWarning):
313+
generic_result = eso.query_surveys(surveys=survey)
296314

297-
assert isinstance(generic_result, Table)
298-
assert len(generic_result) > 0, \
299-
f"query_surveys({survey}) returned no records"
315+
else: # Do not expect warnings
316+
generic_result = eso.query_surveys(surveys=survey)
317+
assert isinstance(generic_result, Table)
318+
assert len(generic_result) > 0, \
319+
f"query_surveys({survey}) returned no records"
300320

301321
@pytest.mark.filterwarnings("ignore::pyvo.dal.exceptions.DALOverflowWarning")
302322
def test_mixed_case_instrument(self, tmp_path):

0 commit comments

Comments
 (0)