@@ -45,7 +45,11 @@ def ai_forecast(
4545 result_sql = self ._sql_generator .ai_forecast (
4646 source_sql = input_data .sql , options = options
4747 )
48- return self ._session .read_gbq (result_sql )
48+
49+ # TODO(b/395912450): Once the limitations with local data are
50+ # resolved, consider setting allow_large_results only when expected
51+ # data size is large.
52+ return self ._session .read_gbq_query (result_sql , allow_large_results = True )
4953
5054
5155class BqmlModel (BaseBqml ):
@@ -169,7 +173,10 @@ def explain_predict(
169173 def global_explain (self , options : Mapping [str , bool ]) -> bpd .DataFrame :
170174 sql = self ._sql_generator .ml_global_explain (struct_options = options )
171175 return (
172- self ._session .read_gbq (sql )
176+ # TODO(b/395912450): Once the limitations with local data are
177+ # resolved, consider setting allow_large_results only when expected
178+ # data size is large.
179+ self ._session .read_gbq_query (sql , allow_large_results = True )
173180 .sort_values (by = "attribution" , ascending = False )
174181 .set_index ("feature" )
175182 )
@@ -244,26 +251,49 @@ def forecast(self, options: Mapping[str, int | float]) -> bpd.DataFrame:
244251 sql = self ._sql_generator .ml_forecast (struct_options = options )
245252 timestamp_col_name = "forecast_timestamp"
246253 index_cols = [timestamp_col_name ]
247- first_col_name = self ._session .read_gbq (sql ).columns .values [0 ]
254+ # TODO(b/395912450): Once the limitations with local data are
255+ # resolved, consider setting allow_large_results only when expected
256+ # data size is large.
257+ first_col_name = self ._session .read_gbq_query (
258+ sql , allow_large_results = True
259+ ).columns .values [0 ]
248260 if timestamp_col_name != first_col_name :
249261 index_cols .append (first_col_name )
250- return self ._session .read_gbq (sql , index_col = index_cols ).reset_index ()
262+ # TODO(b/395912450): Once the limitations with local data are
263+ # resolved, consider setting allow_large_results only when expected
264+ # data size is large.
265+ return self ._session .read_gbq_query (
266+ sql , index_col = index_cols , allow_large_results = True
267+ ).reset_index ()
251268
252269 def explain_forecast (self , options : Mapping [str , int | float ]) -> bpd .DataFrame :
253270 sql = self ._sql_generator .ml_explain_forecast (struct_options = options )
254271 timestamp_col_name = "time_series_timestamp"
255272 index_cols = [timestamp_col_name ]
256- first_col_name = self ._session .read_gbq (sql ).columns .values [0 ]
273+ # TODO(b/395912450): Once the limitations with local data are
274+ # resolved, consider setting allow_large_results only when expected
275+ # data size is large.
276+ first_col_name = self ._session .read_gbq_query (
277+ sql , allow_large_results = True
278+ ).columns .values [0 ]
257279 if timestamp_col_name != first_col_name :
258280 index_cols .append (first_col_name )
259- return self ._session .read_gbq (sql , index_col = index_cols ).reset_index ()
281+ # TODO(b/395912450): Once the limitations with local data are
282+ # resolved, consider setting allow_large_results only when expected
283+ # data size is large.
284+ return self ._session .read_gbq_query (
285+ sql , index_col = index_cols , allow_large_results = True
286+ ).reset_index ()
260287
261288 def evaluate (self , input_data : Optional [bpd .DataFrame ] = None ):
262289 sql = self ._sql_generator .ml_evaluate (
263290 input_data .sql if (input_data is not None ) else None
264291 )
265292
266- return self ._session .read_gbq (sql )
293+ # TODO(b/395912450): Once the limitations with local data are
294+ # resolved, consider setting allow_large_results only when expected
295+ # data size is large.
296+ return self ._session .read_gbq_query (sql , allow_large_results = True )
267297
268298 def llm_evaluate (
269299 self ,
@@ -272,42 +302,62 @@ def llm_evaluate(
272302 ):
273303 sql = self ._sql_generator .ml_llm_evaluate (input_data .sql , task_type )
274304
275- return self ._session .read_gbq (sql )
305+ # TODO(b/395912450): Once the limitations with local data are
306+ # resolved, consider setting allow_large_results only when expected
307+ # data size is large.
308+ return self ._session .read_gbq_query (sql , allow_large_results = True )
276309
277310 def arima_evaluate (self , show_all_candidate_models : bool = False ):
278311 sql = self ._sql_generator .ml_arima_evaluate (show_all_candidate_models )
279312
280- return self ._session .read_gbq (sql )
313+ # TODO(b/395912450): Once the limitations with local data are
314+ # resolved, consider setting allow_large_results only when expected
315+ # data size is large.
316+ return self ._session .read_gbq_query (sql , allow_large_results = True )
281317
282318 def arima_coefficients (self ) -> bpd .DataFrame :
283319 sql = self ._sql_generator .ml_arima_coefficients ()
284320
285- return self ._session .read_gbq (sql )
321+ # TODO(b/395912450): Once the limitations with local data are
322+ # resolved, consider setting allow_large_results only when expected
323+ # data size is large.
324+ return self ._session .read_gbq_query (sql , allow_large_results = True )
286325
287326 def centroids (self ) -> bpd .DataFrame :
288327 assert self ._model .model_type == "KMEANS"
289328
290329 sql = self ._sql_generator .ml_centroids ()
291330
292- return self ._session .read_gbq (
293- sql , index_col = ["centroid_id" , "feature" ]
331+ # TODO(b/395912450): Once the limitations with local data are
332+ # resolved, consider setting allow_large_results only when expected
333+ # data size is large.
334+ return self ._session .read_gbq_query (
335+ sql , index_col = ["centroid_id" , "feature" ], allow_large_results = True
294336 ).reset_index ()
295337
296338 def principal_components (self ) -> bpd .DataFrame :
297339 assert self ._model .model_type == "PCA"
298340
299341 sql = self ._sql_generator .ml_principal_components ()
300342
301- return self ._session .read_gbq (
302- sql , index_col = ["principal_component_id" , "feature" ]
343+ # TODO(b/395912450): Once the limitations with local data are
344+ # resolved, consider setting allow_large_results only when expected
345+ # data size is large.
346+ return self ._session .read_gbq_query (
347+ sql ,
348+ index_col = ["principal_component_id" , "feature" ],
349+ allow_large_results = True ,
303350 ).reset_index ()
304351
305352 def principal_component_info (self ) -> bpd .DataFrame :
306353 assert self ._model .model_type == "PCA"
307354
308355 sql = self ._sql_generator .ml_principal_component_info ()
309356
310- return self ._session .read_gbq (sql )
357+ # TODO(b/395912450): Once the limitations with local data are
358+ # resolved, consider setting allow_large_results only when expected
359+ # data size is large.
360+ return self ._session .read_gbq_query (sql , allow_large_results = True )
311361
312362 def copy (self , new_model_name : str , replace : bool = False ) -> BqmlModel :
313363 job_config = self ._session ._prepare_copy_job_config ()
0 commit comments