@@ -1778,7 +1778,8 @@ def test_to_arrow_w_unknown_type(self):
1778
1778
api_request = mock .Mock (return_value = {"rows" : rows })
1779
1779
row_iterator = self ._make_one (_mock_client (), api_request , path , schema )
1780
1780
1781
- tbl = row_iterator .to_arrow (create_bqstorage_client = False )
1781
+ with warnings .catch_warnings (record = True ) as warned :
1782
+ tbl = row_iterator .to_arrow (create_bqstorage_client = False )
1782
1783
1783
1784
self .assertIsInstance (tbl , pyarrow .Table )
1784
1785
self .assertEqual (tbl .num_rows , 2 )
@@ -1799,6 +1800,10 @@ def test_to_arrow_w_unknown_type(self):
1799
1800
self .assertEqual (ages , [33 , 29 ])
1800
1801
self .assertEqual (sports , ["volleyball" , "basketball" ])
1801
1802
1803
+ self .assertEqual (len (warned ), 1 )
1804
+ warning = warned [0 ]
1805
+ self .assertTrue ("sport" in str (warning ))
1806
+
1802
1807
@unittest .skipIf (pyarrow is None , "Requires `pyarrow`" )
1803
1808
def test_to_arrow_w_empty_table (self ):
1804
1809
from google .cloud .bigquery .schema import SchemaField
@@ -2370,13 +2375,18 @@ def test_to_dataframe_progress_bar_wo_pyarrow(
2370
2375
for progress_bar_type , progress_bar_mock in progress_bars :
2371
2376
row_iterator = self ._make_one (_mock_client (), api_request , path , schema )
2372
2377
with mock .patch ("google.cloud.bigquery.table.pyarrow" , None ):
2373
- df = row_iterator .to_dataframe (progress_bar_type = progress_bar_type )
2378
+ with warnings .catch_warnings (record = True ) as warned :
2379
+ df = row_iterator .to_dataframe (progress_bar_type = progress_bar_type )
2374
2380
2375
2381
progress_bar_mock .assert_called ()
2376
2382
progress_bar_mock ().update .assert_called ()
2377
2383
progress_bar_mock ().close .assert_called_once ()
2378
2384
self .assertEqual (len (df ), 4 )
2379
2385
2386
+ self .assertEqual (len (warned ), 1 )
2387
+ warning = warned [0 ]
2388
+ self .assertTrue ("without pyarrow" in str (warning ))
2389
+
2380
2390
@unittest .skipIf (pandas is None , "Requires `pandas`" )
2381
2391
@mock .patch ("google.cloud.bigquery.table.tqdm" , new = None )
2382
2392
def test_to_dataframe_no_tqdm_no_progress_bar (self ):
@@ -2499,12 +2509,17 @@ def test_to_dataframe_w_empty_results_wo_pyarrow(self):
2499
2509
api_request = mock .Mock (return_value = {"rows" : []})
2500
2510
row_iterator = self ._make_one (_mock_client (), api_request , schema = schema )
2501
2511
2502
- df = row_iterator .to_dataframe ()
2512
+ with warnings .catch_warnings (record = True ) as warned :
2513
+ df = row_iterator .to_dataframe ()
2503
2514
2504
2515
self .assertIsInstance (df , pandas .DataFrame )
2505
2516
self .assertEqual (len (df ), 0 ) # verify the number of rows
2506
2517
self .assertEqual (list (df ), ["name" , "age" ]) # verify the column names
2507
2518
2519
+ self .assertEqual (len (warned ), 1 )
2520
+ warning = warned [0 ]
2521
+ self .assertTrue ("without pyarrow" in str (warning ))
2522
+
2508
2523
@unittest .skipIf (pandas is None , "Requires `pandas`" )
2509
2524
def test_to_dataframe_w_no_results_wo_pyarrow (self ):
2510
2525
from google .cloud .bigquery .schema import SchemaField
@@ -2522,12 +2537,17 @@ def empty_iterable(dtypes=None):
2522
2537
2523
2538
row_iterator .to_dataframe_iterable = empty_iterable
2524
2539
2525
- df = row_iterator .to_dataframe ()
2540
+ with warnings .catch_warnings (record = True ) as warned :
2541
+ df = row_iterator .to_dataframe ()
2526
2542
2527
2543
self .assertIsInstance (df , pandas .DataFrame )
2528
2544
self .assertEqual (len (df ), 0 ) # verify the number of rows
2529
2545
self .assertEqual (list (df ), ["name" , "age" ]) # verify the column names
2530
2546
2547
+ self .assertEqual (len (warned ), 1 )
2548
+ warning = warned [0 ]
2549
+ self .assertTrue ("without pyarrow" in str (warning ))
2550
+
2531
2551
@unittest .skipIf (pandas is None , "Requires `pandas`" )
2532
2552
def test_to_dataframe_w_various_types_nullable (self ):
2533
2553
import datetime
@@ -2787,11 +2807,19 @@ def test_to_dataframe_w_bqstorage_v1beta1_no_streams(self):
2787
2807
table = mut .TableReference .from_string ("proj.dset.tbl" ),
2788
2808
)
2789
2809
2790
- got = row_iterator .to_dataframe (bqstorage_client )
2810
+ with warnings .catch_warnings (record = True ) as warned :
2811
+ got = row_iterator .to_dataframe (bqstorage_client )
2812
+
2791
2813
column_names = ["colA" , "colC" , "colB" ]
2792
2814
self .assertEqual (list (got ), column_names )
2793
2815
self .assertTrue (got .empty )
2794
2816
2817
+ self .assertEqual (len (warned ), 1 )
2818
+ warning = warned [0 ]
2819
+ self .assertTrue (
2820
+ "Support for BigQuery Storage v1beta1 clients is deprecated" in str (warning )
2821
+ )
2822
+
2795
2823
@unittest .skipIf (
2796
2824
bigquery_storage_v1 is None , "Requires `google-cloud-bigquery-storage`"
2797
2825
)
@@ -3493,7 +3521,10 @@ def test_to_dataframe_concat_categorical_dtype_wo_pyarrow(self):
3493
3521
3494
3522
row_iterator = self ._make_one (_mock_client (), api_request , path , schema )
3495
3523
3496
- with mock .patch ("google.cloud.bigquery.table.pyarrow" , None ):
3524
+ mock_pyarrow = mock .patch ("google.cloud.bigquery.table.pyarrow" , None )
3525
+ catch_warnings = warnings .catch_warnings (record = True )
3526
+
3527
+ with mock_pyarrow , catch_warnings as warned :
3497
3528
got = row_iterator .to_dataframe (
3498
3529
dtypes = {
3499
3530
"col_category" : pandas .core .dtypes .dtypes .CategoricalDtype (
@@ -3522,6 +3553,10 @@ def test_to_dataframe_concat_categorical_dtype_wo_pyarrow(self):
3522
3553
["low" , "medium" , "low" , "medium" , "high" , "low" ],
3523
3554
)
3524
3555
3556
+ self .assertEqual (len (warned ), 1 )
3557
+ warning = warned [0 ]
3558
+ self .assertTrue ("without pyarrow" in str (warning ))
3559
+
3525
3560
3526
3561
class TestPartitionRange (unittest .TestCase ):
3527
3562
def _get_target_class (self ):
0 commit comments