1818if typing .TYPE_CHECKING : # pragma: NO COVER
1919 import pandas
2020
21- # Required dependencies, but treat as optional so that _test_google_api_imports
22- # can provide a better error message.
23- try :
24- from google .api_core import exceptions as google_exceptions
25- from google .cloud import bigquery
26- except ImportError : # pragma: NO COVER
27- bigquery = None
28- google_exceptions = None
29-
3021from pandas_gbq .exceptions import (
3122 AccessDenied ,
3223 GenericGBQException ,
33- PerformanceWarning ,
3424)
35- from pandas_gbq import features
3625from pandas_gbq .features import FEATURES
3726import pandas_gbq .schema
3827import pandas_gbq .timestamp
4837def _test_google_api_imports ():
4938 try :
5039 import pkg_resources # noqa
51- except ImportError as ex :
40+ except ImportError as ex : # pragma: NO COVER
5241 raise ImportError ("pandas-gbq requires setuptools" ) from ex
5342
5443 try :
5544 import db_dtypes # noqa
56- except ImportError as ex :
45+ except ImportError as ex : # pragma: NO COVER
5746 raise ImportError ("pandas-gbq requires db-dtypes" ) from ex
5847
5948 try :
6049 import pydata_google_auth # noqa
61- except ImportError as ex :
50+ except ImportError as ex : # pragma: NO COVER
6251 raise ImportError ("pandas-gbq requires pydata-google-auth" ) from ex
6352
6453 try :
6554 from google_auth_oauthlib .flow import InstalledAppFlow # noqa
66- except ImportError as ex :
55+ except ImportError as ex : # pragma: NO COVER
6756 raise ImportError ("pandas-gbq requires google-auth-oauthlib" ) from ex
6857
6958 try :
7059 import google .auth # noqa
71- except ImportError as ex :
60+ except ImportError as ex : # pragma: NO COVER
7261 raise ImportError ("pandas-gbq requires google-auth" ) from ex
7362
7463 try :
7564 from google .cloud import bigquery # noqa
76- except ImportError as ex :
65+ except ImportError as ex : # pragma: NO COVER
7766 raise ImportError ("pandas-gbq requires google-cloud-bigquery" ) from ex
7867
7968
@@ -372,23 +361,17 @@ def sizeof_fmt(num, suffix="B"):
372361
373362 def get_client (self ):
374363 import google .api_core .client_info
364+ from google .cloud import bigquery
375365 import pandas
376366
377367 client_info = google .api_core .client_info .ClientInfo (
378368 user_agent = "pandas-{}" .format (pandas .__version__ )
379369 )
380-
381- # In addition to new enough version of google-api-core, a new enough
382- # version of google-cloud-bigquery is required to populate the
383- # client_info.
384- if FEATURES .bigquery_has_client_info :
385- return bigquery .Client (
386- project = self .project_id ,
387- credentials = self .credentials ,
388- client_info = client_info ,
389- )
390-
391- return bigquery .Client (project = self .project_id , credentials = self .credentials )
370+ return bigquery .Client (
371+ project = self .project_id ,
372+ credentials = self .credentials ,
373+ client_info = client_info ,
374+ )
392375
393376 @staticmethod
394377 def process_http_error (ex ):
@@ -404,6 +387,8 @@ def download_table(
404387 progress_bar_type : Optional [str ] = None ,
405388 dtypes : Optional [Dict [str , Union [str , Any ]]] = None ,
406389 ) -> "pandas.DataFrame" :
390+ from google .cloud import bigquery
391+
407392 self ._start_timer ()
408393
409394 try :
@@ -424,6 +409,7 @@ def download_table(
424409 def run_query (self , query , max_results = None , progress_bar_type = None , ** kwargs ):
425410 from concurrent .futures import TimeoutError
426411 from google .auth .exceptions import RefreshError
412+ from google .cloud import bigquery
427413
428414 job_config = {
429415 "query" : {
@@ -529,27 +515,11 @@ def _download_results(
529515 if user_dtypes is None :
530516 user_dtypes = {}
531517
532- if self .use_bqstorage_api and not FEATURES .bigquery_has_bqstorage :
533- warnings .warn (
534- (
535- "use_bqstorage_api was set, but have google-cloud-bigquery "
536- "version {}. Requires google-cloud-bigquery version "
537- "{} or later."
538- ).format (
539- FEATURES .bigquery_installed_version ,
540- features .BIGQUERY_BQSTORAGE_VERSION ,
541- ),
542- PerformanceWarning ,
543- stacklevel = 4 ,
544- )
545-
546518 create_bqstorage_client = self .use_bqstorage_api
547519 if max_results is not None :
548520 create_bqstorage_client = False
549521
550522 to_dataframe_kwargs = {}
551- if FEATURES .bigquery_has_bqstorage :
552- to_dataframe_kwargs ["create_bqstorage_client" ] = create_bqstorage_client
553523 if FEATURES .bigquery_needs_date_as_object :
554524 to_dataframe_kwargs ["date_as_object" ] = True
555525
@@ -560,6 +530,7 @@ def _download_results(
560530 df = rows_iter .to_dataframe (
561531 dtypes = conversion_dtypes ,
562532 progress_bar_type = progress_bar_type ,
533+ create_bqstorage_client = create_bqstorage_client ,
563534 ** to_dataframe_kwargs ,
564535 )
565536 except self .http_error as ex :
@@ -1051,6 +1022,9 @@ def to_gbq(
10511022
10521023 _test_google_api_imports ()
10531024
1025+ from google .api_core import exceptions as google_exceptions
1026+ from google .cloud import bigquery
1027+
10541028 if verbose is not None and FEATURES .pandas_has_deprecated_verbose :
10551029 warnings .warn (
10561030 "verbose is deprecated and will be removed in "
0 commit comments