3535except ImportError :
3636 pandas = None
3737
38+ try :
39+ import pandas_gbq .schema .pandas_to_bigquery
40+ except ImportError :
41+ pandas_gbq = None
42+
3843try :
3944 import geopandas
4045except ImportError :
@@ -1281,7 +1286,21 @@ def test_dataframe_to_parquet_compression_method(module_under_test):
12811286
12821287
12831288@pytest .mark .skipif (pandas is None , reason = "Requires `pandas`" )
1284- def test_dataframe_to_bq_schema_w_named_index (module_under_test ):
1289+ @pytest .mark .skipif (pandas_gbq is None , reason = "Requires `pandas-gbq`" )
1290+ def test_dataframe_to_bq_schema_returns_schema_with_pandas_gbq (
1291+ module_under_test , monkeypatch
1292+ ):
1293+ monkeypatch .setattr (module_under_test , "pandas_gbq" , None )
1294+ dataframe = pandas .DataFrame ({"field00" : ["foo" , "bar" ]})
1295+ got = module_under_test .dataframe_to_bq_schema (dataframe , [])
1296+ # Don't assert beyond this, since pandas-gbq is now source of truth.
1297+ assert got is not None
1298+
1299+
1300+ @pytest .mark .skipif (pandas is None , reason = "Requires `pandas`" )
1301+ def test_dataframe_to_bq_schema_w_named_index (module_under_test , monkeypatch ):
1302+ monkeypatch .setattr (module_under_test , "pandas_gbq" , None )
1303+
12851304 df_data = collections .OrderedDict (
12861305 [
12871306 ("str_column" , ["hello" , "world" ]),
@@ -1292,7 +1311,8 @@ def test_dataframe_to_bq_schema_w_named_index(module_under_test):
12921311 index = pandas .Index (["a" , "b" ], name = "str_index" )
12931312 dataframe = pandas .DataFrame (df_data , index = index )
12941313
1295- returned_schema = module_under_test .dataframe_to_bq_schema (dataframe , [])
1314+ with pytest .warns (FutureWarning , match = "pandas-gbq" ):
1315+ returned_schema = module_under_test .dataframe_to_bq_schema (dataframe , [])
12961316
12971317 expected_schema = (
12981318 schema .SchemaField ("str_index" , "STRING" , "NULLABLE" ),
@@ -1304,7 +1324,9 @@ def test_dataframe_to_bq_schema_w_named_index(module_under_test):
13041324
13051325
13061326@pytest .mark .skipif (pandas is None , reason = "Requires `pandas`" )
1307- def test_dataframe_to_bq_schema_w_multiindex (module_under_test ):
1327+ def test_dataframe_to_bq_schema_w_multiindex (module_under_test , monkeypatch ):
1328+ monkeypatch .setattr (module_under_test , "pandas_gbq" , None )
1329+
13081330 df_data = collections .OrderedDict (
13091331 [
13101332 ("str_column" , ["hello" , "world" ]),
@@ -1321,7 +1343,8 @@ def test_dataframe_to_bq_schema_w_multiindex(module_under_test):
13211343 )
13221344 dataframe = pandas .DataFrame (df_data , index = index )
13231345
1324- returned_schema = module_under_test .dataframe_to_bq_schema (dataframe , [])
1346+ with pytest .warns (FutureWarning , match = "pandas-gbq" ):
1347+ returned_schema = module_under_test .dataframe_to_bq_schema (dataframe , [])
13251348
13261349 expected_schema = (
13271350 schema .SchemaField ("str_index" , "STRING" , "NULLABLE" ),
@@ -1335,7 +1358,9 @@ def test_dataframe_to_bq_schema_w_multiindex(module_under_test):
13351358
13361359
13371360@pytest .mark .skipif (pandas is None , reason = "Requires `pandas`" )
1338- def test_dataframe_to_bq_schema_w_bq_schema (module_under_test ):
1361+ def test_dataframe_to_bq_schema_w_bq_schema (module_under_test , monkeypatch ):
1362+ monkeypatch .setattr (module_under_test , "pandas_gbq" , None )
1363+
13391364 df_data = collections .OrderedDict (
13401365 [
13411366 ("str_column" , ["hello" , "world" ]),
@@ -1350,7 +1375,10 @@ def test_dataframe_to_bq_schema_w_bq_schema(module_under_test):
13501375 {"name" : "bool_column" , "type" : "BOOL" , "mode" : "REQUIRED" },
13511376 ]
13521377
1353- returned_schema = module_under_test .dataframe_to_bq_schema (dataframe , dict_schema )
1378+ with pytest .warns (FutureWarning , match = "pandas-gbq" ):
1379+ returned_schema = module_under_test .dataframe_to_bq_schema (
1380+ dataframe , dict_schema
1381+ )
13541382
13551383 expected_schema = (
13561384 schema .SchemaField ("str_column" , "STRING" , "NULLABLE" ),
@@ -1361,7 +1389,11 @@ def test_dataframe_to_bq_schema_w_bq_schema(module_under_test):
13611389
13621390
13631391@pytest .mark .skipif (pandas is None , reason = "Requires `pandas`" )
1364- def test_dataframe_to_bq_schema_fallback_needed_wo_pyarrow (module_under_test ):
1392+ def test_dataframe_to_bq_schema_fallback_needed_wo_pyarrow (
1393+ module_under_test , monkeypatch
1394+ ):
1395+ monkeypatch .setattr (module_under_test , "pandas_gbq" , None )
1396+
13651397 dataframe = pandas .DataFrame (
13661398 data = [
13671399 {"id" : 10 , "status" : "FOO" , "execution_date" : datetime .date (2019 , 5 , 10 )},
@@ -1389,7 +1421,11 @@ def test_dataframe_to_bq_schema_fallback_needed_wo_pyarrow(module_under_test):
13891421
13901422@pytest .mark .skipif (pandas is None , reason = "Requires `pandas`" )
13911423@pytest .mark .skipif (isinstance (pyarrow , mock .Mock ), reason = "Requires `pyarrow`" )
1392- def test_dataframe_to_bq_schema_fallback_needed_w_pyarrow (module_under_test ):
1424+ def test_dataframe_to_bq_schema_fallback_needed_w_pyarrow (
1425+ module_under_test , monkeypatch
1426+ ):
1427+ monkeypatch .setattr (module_under_test , "pandas_gbq" , None )
1428+
13931429 dataframe = pandas .DataFrame (
13941430 data = [
13951431 {"id" : 10 , "status" : "FOO" , "created_at" : datetime .date (2019 , 5 , 10 )},
@@ -1419,7 +1455,9 @@ def test_dataframe_to_bq_schema_fallback_needed_w_pyarrow(module_under_test):
14191455
14201456@pytest .mark .skipif (pandas is None , reason = "Requires `pandas`" )
14211457@pytest .mark .skipif (isinstance (pyarrow , mock .Mock ), reason = "Requires `pyarrow`" )
1422- def test_dataframe_to_bq_schema_pyarrow_fallback_fails (module_under_test ):
1458+ def test_dataframe_to_bq_schema_pyarrow_fallback_fails (module_under_test , monkeypatch ):
1459+ monkeypatch .setattr (module_under_test , "pandas_gbq" , None )
1460+
14231461 dataframe = pandas .DataFrame (
14241462 data = [
14251463 {"struct_field" : {"one" : 2 }, "status" : "FOO" },
@@ -1443,9 +1481,11 @@ def test_dataframe_to_bq_schema_pyarrow_fallback_fails(module_under_test):
14431481
14441482
14451483@pytest .mark .skipif (geopandas is None , reason = "Requires `geopandas`" )
1446- def test_dataframe_to_bq_schema_geography (module_under_test ):
1484+ def test_dataframe_to_bq_schema_geography (module_under_test , monkeypatch ):
14471485 from shapely import wkt
14481486
1487+ monkeypatch .setattr (module_under_test , "pandas_gbq" , None )
1488+
14491489 df = geopandas .GeoDataFrame (
14501490 pandas .DataFrame (
14511491 dict (
@@ -1456,7 +1496,10 @@ def test_dataframe_to_bq_schema_geography(module_under_test):
14561496 ),
14571497 geometry = "geo1" ,
14581498 )
1459- bq_schema = module_under_test .dataframe_to_bq_schema (df , [])
1499+
1500+ with pytest .warns (FutureWarning , match = "pandas-gbq" ):
1501+ bq_schema = module_under_test .dataframe_to_bq_schema (df , [])
1502+
14601503 assert bq_schema == (
14611504 schema .SchemaField ("name" , "STRING" ),
14621505 schema .SchemaField ("geo1" , "GEOGRAPHY" ),
0 commit comments