@@ -895,7 +895,7 @@ 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 , dataset_id , reauth = reauth , private_key = private_key , location = location
899
899
)
900
900
901
901
if not table_schema :
@@ -967,9 +967,9 @@ def _generate_bq_schema(df, default_type="STRING"):
967
967
968
968
969
969
class _Table (GbqConnector ):
970
- def __init__ (self , project_id , dataset_id , reauth = False , private_key = None ):
970
+ def __init__ (self , project_id , dataset_id , reauth = False , private_key = None , location = None ):
971
971
self .dataset_id = dataset_id
972
- super (_Table , self ).__init__ (project_id , reauth , private_key )
972
+ super (_Table , self ).__init__ (project_id , reauth , private_key , location = location )
973
973
974
974
def exists (self , table_id ):
975
975
""" Check if a table exists in Google BigQuery
@@ -1017,7 +1017,7 @@ def create(self, table_id, schema):
1017
1017
if not _Dataset (self .project_id , private_key = self .private_key ).exists (
1018
1018
self .dataset_id
1019
1019
):
1020
- _Dataset (self .project_id , private_key = self .private_key ).create (
1020
+ _Dataset (self .project_id , private_key = self .private_key , location = self . location ).create (
1021
1021
self .dataset_id
1022
1022
)
1023
1023
@@ -1064,8 +1064,8 @@ def delete(self, table_id):
1064
1064
1065
1065
1066
1066
class _Dataset (GbqConnector ):
1067
- def __init__ (self , project_id , reauth = False , private_key = None ):
1068
- super (_Dataset , self ).__init__ (project_id , reauth , private_key )
1067
+ def __init__ (self , project_id , reauth = False , private_key = None , location = None ):
1068
+ super (_Dataset , self ).__init__ (project_id , reauth , private_key , location = location )
1069
1069
1070
1070
def exists (self , dataset_id ):
1071
1071
""" Check if a dataset exists in Google BigQuery
@@ -1106,6 +1106,9 @@ def create(self, dataset_id):
1106
1106
)
1107
1107
1108
1108
dataset = Dataset (self .client .dataset (dataset_id ))
1109
+
1110
+ if self .location is not None :
1111
+ dataset .location = self .location
1109
1112
1110
1113
try :
1111
1114
self .client .create_dataset (dataset )
0 commit comments