@@ -121,7 +121,20 @@ class InvalidSchema(ValueError):
121
121
table in BigQuery.
122
122
"""
123
123
124
- pass
124
+ def __init__ (
125
+ self , message : str , local_schema : Dict [str , Any ], remote_schema : Dict [str , Any ]
126
+ ):
127
+ super ().__init__ (message )
128
+ self ._local_schema = local_schema
129
+ self ._remote_schema = remote_schema
130
+
131
+ @property
132
+ def local_schema (self ) -> Dict [str , Any ]:
133
+ return self ._local_schema
134
+
135
+ @property
136
+ def remote_schema (self ) -> Dict [str , Any ]:
137
+ return self ._remote_schema
125
138
126
139
127
140
class NotFoundException (ValueError ):
@@ -354,19 +367,12 @@ def sizeof_fmt(num, suffix="B"):
354
367
return fmt % (num , "Y" , suffix )
355
368
356
369
def get_client (self ):
370
+ import google .api_core .client_info
357
371
import pandas
358
372
359
- try :
360
- # This module was added in google-api-core 1.11.0.
361
- # We don't have a hard requirement on that version, so only
362
- # populate the client_info if available.
363
- import google .api_core .client_info
364
-
365
- client_info = google .api_core .client_info .ClientInfo (
366
- user_agent = "pandas-{}" .format (pandas .__version__ )
367
- )
368
- except ImportError :
369
- client_info = None
373
+ client_info = google .api_core .client_info .ClientInfo (
374
+ user_agent = "pandas-{}" .format (pandas .__version__ )
375
+ )
370
376
371
377
# In addition to new enough version of google-api-core, a new enough
372
378
# version of google-cloud-bigquery is required to populate the
@@ -1057,7 +1063,7 @@ def to_gbq(
1057
1063
DeprecationWarning ,
1058
1064
stacklevel = 2 ,
1059
1065
)
1060
- elif api_method == "load_csv" :
1066
+ else :
1061
1067
warnings .warn (
1062
1068
"chunksize will be ignored when using api_method='load_csv' in a future version of pandas-gbq" ,
1063
1069
PendingDeprecationWarning ,
@@ -1122,12 +1128,14 @@ def to_gbq(
1122
1128
)
1123
1129
elif if_exists == "replace" :
1124
1130
connector .delete_and_recreate_table (dataset_id , table_id , table_schema )
1125
- elif if_exists == "append" :
1131
+ else :
1126
1132
if not pandas_gbq .schema .schema_is_subset (original_schema , table_schema ):
1127
1133
raise InvalidSchema (
1128
1134
"Please verify that the structure and "
1129
1135
"data types in the DataFrame match the "
1130
- "schema of the destination table."
1136
+ "schema of the destination table." ,
1137
+ table_schema ,
1138
+ original_schema ,
1131
1139
)
1132
1140
1133
1141
# Update the local `table_schema` so mode (NULLABLE/REQUIRED)
@@ -1283,9 +1291,6 @@ def delete(self, table_id):
1283
1291
"""
1284
1292
from google .api_core .exceptions import NotFound
1285
1293
1286
- if not self .exists (table_id ):
1287
- raise NotFoundException ("Table does not exist" )
1288
-
1289
1294
table_ref = self ._table_ref (table_id )
1290
1295
try :
1291
1296
self .client .delete_table (table_ref )
0 commit comments