@@ -283,7 +283,7 @@ def __init__(
283283
284284 # BQ Queries costs $5 per TB. First 1 TB per month is free
285285 # see here for more: https://cloud.google.com/bigquery/pricing
286- self .query_price_for_TB = 5. / 2 ** 40 # USD/TB
286+ self .query_price_for_TB = 5.0 / 2 ** 40 # USD/TB
287287
288288 def _start_timer (self ):
289289 self .start = time .time ()
@@ -895,7 +895,11 @@ def to_gbq(
895895 dataset_id , table_id = destination_table .rsplit ("." , 1 )
896896
897897 table = _Table (
898- project_id , dataset_id , reauth = reauth , private_key = private_key
898+ project_id ,
899+ dataset_id ,
900+ reauth = reauth ,
901+ private_key = private_key ,
902+ location = location ,
899903 )
900904
901905 if not table_schema :
@@ -967,9 +971,18 @@ def _generate_bq_schema(df, default_type="STRING"):
967971
968972
969973class _Table (GbqConnector ):
970- def __init__ (self , project_id , dataset_id , reauth = False , private_key = None ):
974+ def __init__ (
975+ self ,
976+ project_id ,
977+ dataset_id ,
978+ reauth = False ,
979+ private_key = None ,
980+ location = None ,
981+ ):
971982 self .dataset_id = dataset_id
972- super (_Table , self ).__init__ (project_id , reauth , private_key )
983+ super (_Table , self ).__init__ (
984+ project_id , reauth , private_key , location = location
985+ )
973986
974987 def exists (self , table_id ):
975988 """ Check if a table exists in Google BigQuery
@@ -1017,9 +1030,11 @@ def create(self, table_id, schema):
10171030 if not _Dataset (self .project_id , private_key = self .private_key ).exists (
10181031 self .dataset_id
10191032 ):
1020- _Dataset (self .project_id , private_key = self .private_key ).create (
1021- self .dataset_id
1022- )
1033+ _Dataset (
1034+ self .project_id ,
1035+ private_key = self .private_key ,
1036+ location = self .location ,
1037+ ).create (self .dataset_id )
10231038
10241039 table_ref = self .client .dataset (self .dataset_id ).table (table_id )
10251040 table = Table (table_ref )
@@ -1064,8 +1079,12 @@ def delete(self, table_id):
10641079
10651080
10661081class _Dataset (GbqConnector ):
1067- def __init__ (self , project_id , reauth = False , private_key = None ):
1068- super (_Dataset , self ).__init__ (project_id , reauth , private_key )
1082+ def __init__ (
1083+ self , project_id , reauth = False , private_key = None , location = None
1084+ ):
1085+ super (_Dataset , self ).__init__ (
1086+ project_id , reauth , private_key , location = location
1087+ )
10691088
10701089 def exists (self , dataset_id ):
10711090 """ Check if a dataset exists in Google BigQuery
@@ -1107,6 +1126,9 @@ def create(self, dataset_id):
11071126
11081127 dataset = Dataset (self .client .dataset (dataset_id ))
11091128
1129+ if self .location is not None :
1130+ dataset .location = self .location
1131+
11101132 try :
11111133 self .client .create_dataset (dataset )
11121134 except self .http_error as ex :
0 commit comments