@@ -223,23 +223,30 @@ def _get_auth_header(self) -> Dict[str, str]:
223223 else :
224224 return {}
225225
226- def _maybe_warn_about_table_length (self , table ):
226+ def _maybe_warn_about_table_length (self , table_rowlim_plus_one ):
227227 """
228228 Issues a warning when a table is empty or when the
229229 results are truncated
230230 """
231- if len (table ) < 1 :
231+ if len (table_rowlim_plus_one ) < 1 :
232232 warnings .warn ("Query returned no results" , NoResultsWarning )
233233
234- if len (table ) == self .ROW_LIMIT :
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.
235242 warnings .warn (f"Results truncated to { self .ROW_LIMIT } . "
236243 "To retrieve all the records set to None the ROW_LIMIT attribute" ,
237244 MaxResultsWarning )
238245
239246 def _try_download_pyvo_table (self ,
240247 query_str : str ,
241248 tap : TAPService ) -> Optional [Table ]:
242- table_to_return = Table ()
249+ table_with_an_extra_row = Table ()
243250
244251 def message (query_str ):
245252 return (f"Error executing the following query:\n \n "
@@ -249,16 +256,16 @@ def message(query_str):
249256 f' >>> Eso().query_tap( "{ query_str } " )\n \n ' )
250257
251258 try :
252- table_to_return = tap .search (query = query_str , maxrec = self .ROW_LIMIT ).to_table ()
253- self ._maybe_warn_about_table_length (table_to_return )
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 )
254261 except DALQueryError :
255262 log .error (message (query_str ))
256263 except DALFormatError as e :
257264 raise DALFormatError (message (query_str ) + f"cause: { e .cause } " ) from e
258265 except Exception as e :
259266 raise type (e )(f"{ e } \n " + message (query_str )) from e
260267
261- return table_to_return
268+ return table_with_an_extra_row [: self . ROW_LIMIT ]
262269
263270 def tap (self , authenticated : bool = False ) -> TAPService :
264271
0 commit comments