@@ -283,7 +283,7 @@ def __init__(
283
283
284
284
# BQ Queries costs $5 per TB. First 1 TB per month is free
285
285
# 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
287
287
288
288
def _start_timer (self ):
289
289
self .start = time .time ()
@@ -895,7 +895,11 @@ def to_gbq(
895
895
dataset_id , table_id = destination_table .rsplit ("." , 1 )
896
896
897
897
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 ,
899
903
)
900
904
901
905
if not table_schema :
@@ -967,9 +971,18 @@ def _generate_bq_schema(df, default_type="STRING"):
967
971
968
972
969
973
class _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
+ ):
971
982
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
+ )
973
986
974
987
def exists (self , table_id ):
975
988
""" Check if a table exists in Google BigQuery
@@ -1017,9 +1030,11 @@ def create(self, table_id, schema):
1017
1030
if not _Dataset (self .project_id , private_key = self .private_key ).exists (
1018
1031
self .dataset_id
1019
1032
):
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 )
1023
1038
1024
1039
table_ref = self .client .dataset (self .dataset_id ).table (table_id )
1025
1040
table = Table (table_ref )
@@ -1064,8 +1079,12 @@ def delete(self, table_id):
1064
1079
1065
1080
1066
1081
class _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
+ )
1069
1088
1070
1089
def exists (self , dataset_id ):
1071
1090
""" Check if a dataset exists in Google BigQuery
@@ -1107,6 +1126,9 @@ def create(self, dataset_id):
1107
1126
1108
1127
dataset = Dataset (self .client .dataset (dataset_id ))
1109
1128
1129
+ if self .location is not None :
1130
+ dataset .location = self .location
1131
+
1110
1132
try :
1111
1133
self .client .create_dataset (dataset )
1112
1134
except self .http_error as ex :
0 commit comments