@@ -34,7 +34,7 @@ def _check_google_client_version():
34
34
raise ImportError ('Could not import pkg_resources (setuptools).' )
35
35
36
36
# https://github.com/GoogleCloudPlatform/google-cloud-python/blob/master/bigquery/CHANGELOG.md
37
- bigquery_minimum_version = pkg_resources .parse_version ('0.29 .0' )
37
+ bigquery_minimum_version = pkg_resources .parse_version ('0.32 .0' )
38
38
BIGQUERY_INSTALLED_VERSION = pkg_resources .get_distribution (
39
39
'google-cloud-bigquery' ).parsed_version
40
40
@@ -152,12 +152,13 @@ class GbqConnector(object):
152
152
153
153
def __init__ (self , project_id , reauth = False ,
154
154
private_key = None , auth_local_webserver = False ,
155
- dialect = 'legacy' ):
155
+ dialect = 'legacy' , location = None ):
156
156
from google .api_core .exceptions import GoogleAPIError
157
157
from google .api_core .exceptions import ClientError
158
158
from pandas_gbq import auth
159
159
self .http_error = (ClientError , GoogleAPIError )
160
160
self .project_id = project_id
161
+ self .location = location
161
162
self .reauth = reauth
162
163
self .private_key = private_key
163
164
self .auth_local_webserver = auth_local_webserver
@@ -215,9 +216,9 @@ def process_http_error(ex):
215
216
raise GenericGBQException ("Reason: {0}" .format (ex ))
216
217
217
218
def run_query (self , query , ** kwargs ):
218
- from google .auth .exceptions import RefreshError
219
219
from concurrent .futures import TimeoutError
220
- import pandas_gbq .query
220
+ from google .auth .exceptions import RefreshError
221
+ from google .cloud import bigquery
221
222
222
223
job_config = {
223
224
'query' : {
@@ -243,8 +244,8 @@ def run_query(self, query, **kwargs):
243
244
logger .info ('Requesting query... ' )
244
245
query_reply = self .client .query (
245
246
query ,
246
- job_config = pandas_gbq . query . query_config (
247
- job_config , BIGQUERY_INSTALLED_VERSION ) )
247
+ job_config = bigquery . QueryJobConfig . from_api_repr ( job_config ),
248
+ location = self . location )
248
249
logger .info ('ok.\n Query running...' )
249
250
except (RefreshError , ValueError ):
250
251
if self .private_key :
@@ -319,7 +320,7 @@ def load_data(
319
320
try :
320
321
chunks = load .load_chunks (self .client , dataframe , dataset_id ,
321
322
table_id , chunksize = chunksize ,
322
- schema = schema )
323
+ schema = schema , location = self . location )
323
324
if progress_bar and tqdm :
324
325
chunks = tqdm .tqdm (chunks )
325
326
for remaining_rows in chunks :
@@ -470,7 +471,8 @@ def _parse_data(schema, rows):
470
471
471
472
def read_gbq (query , project_id = None , index_col = None , col_order = None ,
472
473
reauth = False , verbose = None , private_key = None ,
473
- auth_local_webserver = False , dialect = 'legacy' , ** kwargs ):
474
+ auth_local_webserver = False , dialect = 'legacy' , location = None ,
475
+ configuration = None ):
474
476
r"""Load data from Google BigQuery using google-cloud-python
475
477
476
478
The main method a user calls to execute a Query in Google BigQuery
@@ -520,17 +522,23 @@ def read_gbq(query, project_id=None, index_col=None, col_order=None,
520
522
compliant with the SQL 2011 standard. For more information
521
523
see `BigQuery SQL Reference
522
524
<https://cloud.google.com/bigquery/sql-reference/>`__
523
- verbose : None, deprecated
524
-
525
- **kwargs : Arbitrary keyword arguments
526
- configuration (dict): query config parameters for job processing.
525
+ location : str (optional)
526
+ Location where the query job should run. See the `BigQuery locations
527
+ <https://cloud.google.com/bigquery/docs/dataset-locations>
528
+ documentation`__ for a list of available locations. The location must
529
+ match that of any datasets used in the query.
530
+ .. versionadded:: 0.5.0
531
+ configuration : dict (optional)
532
+ Query config parameters for job processing.
527
533
For example:
528
534
529
535
configuration = {'query': {'useQueryCache': False}}
530
536
531
537
For more information see `BigQuery SQL Reference
532
538
<https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs#configuration.query>`__
533
539
540
+ verbose : None, deprecated
541
+
534
542
Returns
535
543
-------
536
544
df: DataFrame
@@ -550,9 +558,9 @@ def read_gbq(query, project_id=None, index_col=None, col_order=None,
550
558
raise ValueError ("'{0}' is not valid for dialect" .format (dialect ))
551
559
552
560
connector = GbqConnector (
553
- project_id , reauth = reauth , private_key = private_key ,
554
- dialect = dialect , auth_local_webserver = auth_local_webserver )
555
- schema , rows = connector .run_query (query , ** kwargs )
561
+ project_id , reauth = reauth , private_key = private_key , dialect = dialect ,
562
+ auth_local_webserver = auth_local_webserver , location = location )
563
+ schema , rows = connector .run_query (query , configuration = configuration )
556
564
final_df = _parse_data (schema , rows )
557
565
558
566
# Reindex the DataFrame on the provided column
@@ -595,7 +603,8 @@ def read_gbq(query, project_id=None, index_col=None, col_order=None,
595
603
596
604
def to_gbq (dataframe , destination_table , project_id = None , chunksize = None ,
597
605
verbose = None , reauth = False , if_exists = 'fail' , private_key = None ,
598
- auth_local_webserver = False , table_schema = None , progress_bar = True ):
606
+ auth_local_webserver = False , table_schema = None , location = None ,
607
+ progress_bar = True ):
599
608
"""Write a DataFrame to a Google BigQuery table.
600
609
601
610
The main method a user calls to export pandas DataFrame contents to
@@ -648,9 +657,16 @@ def to_gbq(dataframe, destination_table, project_id=None, chunksize=None,
648
657
of DataFrame columns. See BigQuery API documentation on available
649
658
names of a field.
650
659
.. versionadded:: 0.3.1
651
- verbose : None, deprecated
660
+ location : str (optional)
661
+ Location where the load job should run. See the `BigQuery locations
662
+ <https://cloud.google.com/bigquery/docs/dataset-locations>
663
+ documentation`__ for a list of available locations. The location must
664
+ match that of the target dataset.
665
+ .. versionadded:: 0.5.0
652
666
progress_bar : boolean, True by default. It uses the library `tqdm` to show
653
667
the progress bar for the upload, chunk by chunk.
668
+ .. versionadded:: 0.5.0
669
+ verbose : None, deprecated
654
670
"""
655
671
656
672
_test_google_api_imports ()
@@ -670,7 +686,7 @@ def to_gbq(dataframe, destination_table, project_id=None, chunksize=None,
670
686
671
687
connector = GbqConnector (
672
688
project_id , reauth = reauth , private_key = private_key ,
673
- auth_local_webserver = auth_local_webserver )
689
+ auth_local_webserver = auth_local_webserver , location = location )
674
690
dataset_id , table_id = destination_table .rsplit ('.' , 1 )
675
691
676
692
table = _Table (project_id , dataset_id , reauth = reauth ,
0 commit comments