@@ -1385,6 +1385,40 @@ def test_dataframe_to_bq_schema_w_bq_schema(module_under_test, monkeypatch):
1385
1385
assert returned_schema == expected_schema
1386
1386
1387
1387
1388
+ @pytest .mark .skipif (pandas is None , reason = "Requires `pandas`" )
1389
+ def test_dataframe_to_bq_schema_allows_extra_fields (module_under_test , monkeypatch ):
1390
+ monkeypatch .setattr (module_under_test , "pandas_gbq" , None )
1391
+
1392
+ df_data = collections .OrderedDict (
1393
+ [
1394
+ ("str_column" , ["hello" , "world" ]),
1395
+ ("int_column" , [42 , 8 ]),
1396
+ ("bool_column" , [True , False ]),
1397
+ ]
1398
+ )
1399
+ dataframe = pandas .DataFrame (df_data )
1400
+
1401
+ dict_schema = [
1402
+ {"name" : "str_column" , "type" : "STRING" , "mode" : "NULLABLE" },
1403
+ {"name" : "int_column" , "type" : "INTEGER" , "mode" : "NULLABLE" },
1404
+ {"name" : "bool_column" , "type" : "BOOL" , "mode" : "REQUIRED" },
1405
+ {"name" : "extra_column" , "type" : "STRING" , "mode" : "NULLABLE" },
1406
+ ]
1407
+
1408
+ with pytest .warns (UserWarning , match = "bq_schema contains fields not present" ):
1409
+ returned_schema = module_under_test .dataframe_to_bq_schema (
1410
+ dataframe , dict_schema
1411
+ )
1412
+
1413
+ expected_schema = (
1414
+ schema .SchemaField ("str_column" , "STRING" , "NULLABLE" ),
1415
+ schema .SchemaField ("int_column" , "INTEGER" , "NULLABLE" ),
1416
+ schema .SchemaField ("bool_column" , "BOOL" , "REQUIRED" ),
1417
+ schema .SchemaField ("extra_column" , "STRING" , "NULLABLE" ),
1418
+ )
1419
+ assert returned_schema == expected_schema
1420
+
1421
+
1388
1422
@pytest .mark .skipif (pandas is None , reason = "Requires `pandas`" )
1389
1423
def test_dataframe_to_bq_schema_fallback_needed_wo_pyarrow (
1390
1424
module_under_test , monkeypatch
0 commit comments