@@ -121,7 +121,20 @@ class InvalidSchema(ValueError):
121121 table in BigQuery.
122122 """
123123
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
125138
126139
127140class NotFoundException (ValueError ):
@@ -354,19 +367,12 @@ def sizeof_fmt(num, suffix="B"):
354367 return fmt % (num , "Y" , suffix )
355368
356369 def get_client (self ):
370+ import google .api_core .client_info
357371 import pandas
358372
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+ )
370376
371377 # In addition to new enough version of google-api-core, a new enough
372378 # version of google-cloud-bigquery is required to populate the
@@ -1057,7 +1063,7 @@ def to_gbq(
10571063 DeprecationWarning ,
10581064 stacklevel = 2 ,
10591065 )
1060- elif api_method == "load_csv" :
1066+ else :
10611067 warnings .warn (
10621068 "chunksize will be ignored when using api_method='load_csv' in a future version of pandas-gbq" ,
10631069 PendingDeprecationWarning ,
@@ -1122,12 +1128,14 @@ def to_gbq(
11221128 )
11231129 elif if_exists == "replace" :
11241130 connector .delete_and_recreate_table (dataset_id , table_id , table_schema )
1125- elif if_exists == "append" :
1131+ else :
11261132 if not pandas_gbq .schema .schema_is_subset (original_schema , table_schema ):
11271133 raise InvalidSchema (
11281134 "Please verify that the structure and "
11291135 "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 ,
11311139 )
11321140
11331141 # Update the local `table_schema` so mode (NULLABLE/REQUIRED)
@@ -1283,9 +1291,6 @@ def delete(self, table_id):
12831291 """
12841292 from google .api_core .exceptions import NotFound
12851293
1286- if not self .exists (table_id ):
1287- raise NotFoundException ("Table does not exist" )
1288-
12891294 table_ref = self ._table_ref (table_id )
12901295 try :
12911296 self .client .delete_table (table_ref )
0 commit comments