@@ -328,50 +328,47 @@ def _read_gbq_colab(
328328 if pyformat_args is None :
329329 pyformat_args = {}
330330
331- with warnings .catch_warnings ():
332- warnings .simplefilter ("ignore" , category = FutureWarning )
333-
334- # Only try to set the global location if it's not a dry run. We don't want
335- # to bind to a location too early. This is especially important if the query
336- # only refers to local data and not any BigQuery tables.
337- if dry_run :
338- result = _try_read_gbq_colab_sessionless_dry_run (
339- query_or_table , pyformat_args = pyformat_args
340- )
341-
342- if result is not None :
343- return result
331+ # Only try to set the global location if it's not a dry run. We don't want
332+ # to bind to a location too early. This is especially important if the query
333+ # only refers to local data and not any BigQuery tables.
334+ if dry_run :
335+ result = _try_read_gbq_colab_sessionless_dry_run (
336+ query_or_table , pyformat_args = pyformat_args
337+ )
344338
345- # If we made it this far, we must have a session that has already
346- # started. That means we can safely call the "real" _read_gbq_colab,
347- # which generates slightly nicer SQL.
348- else :
349- # Delay formatting the query with the special "session-less" logic. This
350- # avoids doing unnecessary work if the session already has a location or has
351- # already started.
352- create_query = functools .partial (
353- bigframes .core .pyformat .pyformat ,
354- query_or_table ,
355- pyformat_args = pyformat_args ,
356- dry_run = True ,
357- )
358- _set_default_session_location_if_possible_deferred_query (create_query )
359- if not config .options .bigquery ._session_started :
360- # Don't warning about Polars in SQL cell.
361- # Related to b/437090788.
362- try :
363- bigframes ._importing .import_polars ()
364- warnings .simplefilter ("ignore" , bigframes .exceptions .PreviewWarning )
365- config .options .bigquery .enable_polars_execution = True
366- except ImportError :
367- pass # don't fail if polars isn't available
368-
369- return global_session .with_default_session (
370- bigframes .session .Session ._read_gbq_colab ,
339+ if result is not None :
340+ return result
341+
342+ # If we made it this far, we must have a session that has already
343+ # started. That means we can safely call the "real" _read_gbq_colab,
344+ # which generates slightly nicer SQL.
345+ else :
346+ # Delay formatting the query with the special "session-less" logic. This
347+ # avoids doing unnecessary work if the session already has a location or has
348+ # already started.
349+ create_query = functools .partial (
350+ bigframes .core .pyformat .pyformat ,
371351 query_or_table ,
372352 pyformat_args = pyformat_args ,
373- dry_run = dry_run ,
353+ dry_run = True ,
374354 )
355+ _set_default_session_location_if_possible_deferred_query (create_query )
356+ if not config .options .bigquery ._session_started :
357+ # Don't warning about Polars in SQL cell.
358+ # Related to b/437090788.
359+ try :
360+ bigframes ._importing .import_polars ()
361+ warnings .simplefilter ("ignore" , bigframes .exceptions .PreviewWarning )
362+ config .options .bigquery .enable_polars_execution = True
363+ except ImportError :
364+ pass # don't fail if polars isn't available
365+
366+ return global_session .with_default_session (
367+ bigframes .session .Session ._read_gbq_colab ,
368+ query_or_table ,
369+ pyformat_args = pyformat_args ,
370+ dry_run = dry_run ,
371+ )
375372
376373
377374def read_gbq_model (model_name : str ):
0 commit comments