|
17 | 17 | from __future__ import absolute_import |
18 | 18 |
|
19 | 19 | import collections |
| 20 | +import concurrent.futures |
20 | 21 | import copy |
21 | 22 | import datetime |
22 | 23 | import json |
|
25 | 26 |
|
26 | 27 | import six |
27 | 28 |
|
| 29 | +try: |
| 30 | + from google.cloud import bigquery_storage_v1beta1 |
| 31 | +except ImportError: # pragma: NO COVER |
| 32 | + bigquery_storage_v1beta1 = None |
| 33 | + |
28 | 34 | try: |
29 | 35 | import pandas |
30 | 36 | except ImportError: # pragma: NO COVER |
|
46 | 52 | from google.cloud.bigquery.external_config import ExternalConfig |
47 | 53 |
|
48 | 54 |
|
| 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 | +) |
49 | 59 | _NO_PANDAS_ERROR = ( |
50 | 60 | "The pandas library is not installed, please install " |
51 | 61 | "pandas to use the to_dataframe() function." |
@@ -287,7 +297,8 @@ def to_bqstorage(self): |
287 | 297 | google.cloud.bigquery_storage_v1beta1.types.TableReference: |
288 | 298 | A reference to this table in the BigQuery Storage API. |
289 | 299 | """ |
290 | | - from google.cloud import bigquery_storage_v1beta1 |
| 300 | + if bigquery_storage_v1beta1 is None: |
| 301 | + raise ValueError(_NO_BQSTORAGE_ERROR) |
291 | 302 |
|
292 | 303 | table_ref = bigquery_storage_v1beta1.types.TableReference() |
293 | 304 | table_ref.project_id = self._project |
@@ -1391,8 +1402,8 @@ def _to_dataframe_bqstorage_stream( |
1391 | 1402 |
|
1392 | 1403 | def _to_dataframe_bqstorage(self, bqstorage_client, dtypes): |
1393 | 1404 | """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) |
1396 | 1407 |
|
1397 | 1408 | if "$" in self._table.table_id: |
1398 | 1409 | raise ValueError( |
|
0 commit comments