Skip to content

Commit fa7bb05

Browse files
committed
Import bqstorage dependency at top of module.
1 parent 1099952 commit fa7bb05

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

bigquery/google/cloud/bigquery/table.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from __future__ import absolute_import
1818

1919
import collections
20+
import concurrent.futures
2021
import copy
2122
import datetime
2223
import json
@@ -25,6 +26,11 @@
2526

2627
import six
2728

29+
try:
30+
from google.cloud import bigquery_storage_v1beta1
31+
except ImportError: # pragma: NO COVER
32+
bigquery_storage_v1beta1 = None
33+
2834
try:
2935
import pandas
3036
except ImportError: # pragma: NO COVER
@@ -46,6 +52,10 @@
4652
from google.cloud.bigquery.external_config import ExternalConfig
4753

4854

55+
_NO_PANDAS_ERROR = (
56+
"The google-cloud-bigquery-storage library is not installed, "
57+
"please install google-cloud-bigquery-storage to use bqstorage features."
58+
)
4959
_NO_PANDAS_ERROR = (
5060
"The pandas library is not installed, please install "
5161
"pandas to use the to_dataframe() function."
@@ -287,7 +297,8 @@ def to_bqstorage(self):
287297
google.cloud.bigquery_storage_v1beta1.types.TableReference:
288298
A reference to this table in the BigQuery Storage API.
289299
"""
290-
from google.cloud import bigquery_storage_v1beta1
300+
if bigquery_storage_v1beta1 is None:
301+
raise ValueError(_NO_BQSTORAGE_ERROR)
291302

292303
table_ref = bigquery_storage_v1beta1.types.TableReference()
293304
table_ref.project_id = self._project
@@ -1391,8 +1402,8 @@ def _to_dataframe_bqstorage_stream(
13911402

13921403
def _to_dataframe_bqstorage(self, bqstorage_client, dtypes):
13931404
"""Use (faster, but billable) BQ Storage API to construct DataFrame."""
1394-
import concurrent.futures
1395-
from google.cloud import bigquery_storage_v1beta1
1405+
if bigquery_storage_v1beta1 is None:
1406+
raise ValueError(_NO_BQSTORAGE_ERROR)
13961407

13971408
if "$" in self._table.table_id:
13981409
raise ValueError(

0 commit comments

Comments
 (0)