@@ -8381,8 +8381,12 @@ def test_load_table_from_dataframe_w_automatic_schema_detection_fails(self):
83818381 autospec = True ,
83828382 side_effect = google .api_core .exceptions .NotFound ("Table not found" ),
83838383 )
8384+ pandas_gbq_patch = mock .patch (
8385+ "google.cloud.bigquery._pandas_helpers.pandas_gbq" ,
8386+ new = None ,
8387+ )
83848388
8385- with load_patch as load_table_from_file , get_table_patch :
8389+ with load_patch as load_table_from_file , get_table_patch , pandas_gbq_patch :
83868390 with warnings .catch_warnings (record = True ) as warned :
83878391 client .load_table_from_dataframe (
83888392 dataframe , self .TABLE_REF , location = self .LOCATION
@@ -8438,7 +8442,6 @@ def test_load_table_from_dataframe_w_index_and_auto_schema(self):
84388442 load_patch = mock .patch (
84398443 "google.cloud.bigquery.client.Client.load_table_from_file" , autospec = True
84408444 )
8441-
84428445 get_table_patch = mock .patch (
84438446 "google.cloud.bigquery.client.Client.get_table" ,
84448447 autospec = True ,
@@ -8450,6 +8453,7 @@ def test_load_table_from_dataframe_w_index_and_auto_schema(self):
84508453 ]
84518454 ),
84528455 )
8456+
84538457 with load_patch as load_table_from_file , get_table_patch :
84548458 client .load_table_from_dataframe (
84558459 dataframe , self .TABLE_REF , location = self .LOCATION
@@ -8570,10 +8574,10 @@ def test_load_table_from_dataframe_w_nullable_int64_datatype_automatic_schema(se
85708574
85718575 client = self ._make_client ()
85728576 dataframe = pandas .DataFrame ({"x" : [1 , 2 , None , 4 ]}, dtype = "Int64" )
8577+
85738578 load_patch = mock .patch (
85748579 "google.cloud.bigquery.client.Client.load_table_from_file" , autospec = True
85758580 )
8576-
85778581 get_table_patch = mock .patch (
85788582 "google.cloud.bigquery.client.Client.get_table" ,
85798583 autospec = True ,
@@ -8602,8 +8606,13 @@ def test_load_table_from_dataframe_w_nullable_int64_datatype_automatic_schema(se
86028606
86038607 sent_config = load_table_from_file .mock_calls [0 ][2 ]["job_config" ]
86048608 assert sent_config .source_format == job .SourceFormat .PARQUET
8605- assert tuple (sent_config .schema ) == (
8606- SchemaField ("x" , "INT64" , "NULLABLE" , None ),
8609+ assert (
8610+ # Accept either the GoogleSQL or legacy SQL type name from pandas-gbq.
8611+ tuple (sent_config .schema ) == (
8612+ SchemaField ("x" , "INT64" , "NULLABLE" , None ),
8613+ ) or tuple (sent_config .schema ) == (
8614+ SchemaField ("x" , "INTEGER" , "NULLABLE" , None ),
8615+ )
86078616 )
86088617
86098618 def test_load_table_from_dataframe_struct_fields (self ):
@@ -8749,14 +8758,22 @@ def test_load_table_from_dataframe_array_fields_w_auto_schema(self):
87498758 data = records , columns = ["float_column" , "array_column" ]
87508759 )
87518760
8752- expected_schema = [
8761+ expected_schema_googlesql = [
87538762 SchemaField ("float_column" , "FLOAT" ),
87548763 SchemaField (
87558764 "array_column" ,
87568765 "INT64" ,
87578766 mode = "REPEATED" ,
87588767 ),
87598768 ]
8769+ expected_schema_legacy_sql = [
8770+ SchemaField ("float_column" , "FLOAT" ),
8771+ SchemaField (
8772+ "array_column" ,
8773+ "INTEGER" ,
8774+ mode = "REPEATED" ,
8775+ ),
8776+ ]
87608777
87618778 load_patch = mock .patch (
87628779 "google.cloud.bigquery.client.Client.load_table_from_file" , autospec = True
@@ -8792,7 +8809,7 @@ def test_load_table_from_dataframe_array_fields_w_auto_schema(self):
87928809
87938810 sent_config = load_table_from_file .mock_calls [0 ][2 ]["job_config" ]
87948811 assert sent_config .source_format == job .SourceFormat .PARQUET
8795- assert sent_config .schema == expected_schema
8812+ assert sent_config .schema == expected_schema_googlesql or sent_config . schema == expected_schema_legacy_sql
87968813
87978814 def test_load_table_from_dataframe_w_partial_schema (self ):
87988815 pandas = pytest .importorskip ("pandas" )
0 commit comments