@@ -45,7 +45,11 @@ def ai_forecast(
45
45
result_sql = self ._sql_generator .ai_forecast (
46
46
source_sql = input_data .sql , options = options
47
47
)
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 )
49
53
50
54
51
55
class BqmlModel (BaseBqml ):
@@ -169,7 +173,10 @@ def explain_predict(
169
173
def global_explain (self , options : Mapping [str , bool ]) -> bpd .DataFrame :
170
174
sql = self ._sql_generator .ml_global_explain (struct_options = options )
171
175
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 )
173
180
.sort_values (by = "attribution" , ascending = False )
174
181
.set_index ("feature" )
175
182
)
@@ -244,26 +251,49 @@ def forecast(self, options: Mapping[str, int | float]) -> bpd.DataFrame:
244
251
sql = self ._sql_generator .ml_forecast (struct_options = options )
245
252
timestamp_col_name = "forecast_timestamp"
246
253
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 ]
248
260
if timestamp_col_name != first_col_name :
249
261
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 ()
251
268
252
269
def explain_forecast (self , options : Mapping [str , int | float ]) -> bpd .DataFrame :
253
270
sql = self ._sql_generator .ml_explain_forecast (struct_options = options )
254
271
timestamp_col_name = "time_series_timestamp"
255
272
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 ]
257
279
if timestamp_col_name != first_col_name :
258
280
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 ()
260
287
261
288
def evaluate (self , input_data : Optional [bpd .DataFrame ] = None ):
262
289
sql = self ._sql_generator .ml_evaluate (
263
290
input_data .sql if (input_data is not None ) else None
264
291
)
265
292
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 )
267
297
268
298
def llm_evaluate (
269
299
self ,
@@ -272,42 +302,62 @@ def llm_evaluate(
272
302
):
273
303
sql = self ._sql_generator .ml_llm_evaluate (input_data .sql , task_type )
274
304
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 )
276
309
277
310
def arima_evaluate (self , show_all_candidate_models : bool = False ):
278
311
sql = self ._sql_generator .ml_arima_evaluate (show_all_candidate_models )
279
312
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 )
281
317
282
318
def arima_coefficients (self ) -> bpd .DataFrame :
283
319
sql = self ._sql_generator .ml_arima_coefficients ()
284
320
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 )
286
325
287
326
def centroids (self ) -> bpd .DataFrame :
288
327
assert self ._model .model_type == "KMEANS"
289
328
290
329
sql = self ._sql_generator .ml_centroids ()
291
330
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
294
336
).reset_index ()
295
337
296
338
def principal_components (self ) -> bpd .DataFrame :
297
339
assert self ._model .model_type == "PCA"
298
340
299
341
sql = self ._sql_generator .ml_principal_components ()
300
342
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 ,
303
350
).reset_index ()
304
351
305
352
def principal_component_info (self ) -> bpd .DataFrame :
306
353
assert self ._model .model_type == "PCA"
307
354
308
355
sql = self ._sql_generator .ml_principal_component_info ()
309
356
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 )
311
361
312
362
def copy (self , new_model_name : str , replace : bool = False ) -> BqmlModel :
313
363
job_config = self ._session ._prepare_copy_job_config ()
0 commit comments