@@ -1778,7 +1778,8 @@ def test_to_arrow_w_unknown_type(self):
17781778 api_request = mock .Mock (return_value = {"rows" : rows })
17791779 row_iterator = self ._make_one (_mock_client (), api_request , path , schema )
17801780
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 )
17821783
17831784 self .assertIsInstance (tbl , pyarrow .Table )
17841785 self .assertEqual (tbl .num_rows , 2 )
@@ -1799,6 +1800,10 @@ def test_to_arrow_w_unknown_type(self):
17991800 self .assertEqual (ages , [33 , 29 ])
18001801 self .assertEqual (sports , ["volleyball" , "basketball" ])
18011802
1803+ self .assertEqual (len (warned ), 1 )
1804+ warning = warned [0 ]
1805+ self .assertTrue ("sport" in str (warning ))
1806+
18021807 @unittest .skipIf (pyarrow is None , "Requires `pyarrow`" )
18031808 def test_to_arrow_w_empty_table (self ):
18041809 from google .cloud .bigquery .schema import SchemaField
@@ -2370,13 +2375,18 @@ def test_to_dataframe_progress_bar_wo_pyarrow(
23702375 for progress_bar_type , progress_bar_mock in progress_bars :
23712376 row_iterator = self ._make_one (_mock_client (), api_request , path , schema )
23722377 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 )
23742380
23752381 progress_bar_mock .assert_called ()
23762382 progress_bar_mock ().update .assert_called ()
23772383 progress_bar_mock ().close .assert_called_once ()
23782384 self .assertEqual (len (df ), 4 )
23792385
2386+ self .assertEqual (len (warned ), 1 )
2387+ warning = warned [0 ]
2388+ self .assertTrue ("without pyarrow" in str (warning ))
2389+
23802390 @unittest .skipIf (pandas is None , "Requires `pandas`" )
23812391 @mock .patch ("google.cloud.bigquery.table.tqdm" , new = None )
23822392 def test_to_dataframe_no_tqdm_no_progress_bar (self ):
@@ -2499,12 +2509,17 @@ def test_to_dataframe_w_empty_results_wo_pyarrow(self):
24992509 api_request = mock .Mock (return_value = {"rows" : []})
25002510 row_iterator = self ._make_one (_mock_client (), api_request , schema = schema )
25012511
2502- df = row_iterator .to_dataframe ()
2512+ with warnings .catch_warnings (record = True ) as warned :
2513+ df = row_iterator .to_dataframe ()
25032514
25042515 self .assertIsInstance (df , pandas .DataFrame )
25052516 self .assertEqual (len (df ), 0 ) # verify the number of rows
25062517 self .assertEqual (list (df ), ["name" , "age" ]) # verify the column names
25072518
2519+ self .assertEqual (len (warned ), 1 )
2520+ warning = warned [0 ]
2521+ self .assertTrue ("without pyarrow" in str (warning ))
2522+
25082523 @unittest .skipIf (pandas is None , "Requires `pandas`" )
25092524 def test_to_dataframe_w_no_results_wo_pyarrow (self ):
25102525 from google .cloud .bigquery .schema import SchemaField
@@ -2522,12 +2537,17 @@ def empty_iterable(dtypes=None):
25222537
25232538 row_iterator .to_dataframe_iterable = empty_iterable
25242539
2525- df = row_iterator .to_dataframe ()
2540+ with warnings .catch_warnings (record = True ) as warned :
2541+ df = row_iterator .to_dataframe ()
25262542
25272543 self .assertIsInstance (df , pandas .DataFrame )
25282544 self .assertEqual (len (df ), 0 ) # verify the number of rows
25292545 self .assertEqual (list (df ), ["name" , "age" ]) # verify the column names
25302546
2547+ self .assertEqual (len (warned ), 1 )
2548+ warning = warned [0 ]
2549+ self .assertTrue ("without pyarrow" in str (warning ))
2550+
25312551 @unittest .skipIf (pandas is None , "Requires `pandas`" )
25322552 def test_to_dataframe_w_various_types_nullable (self ):
25332553 import datetime
@@ -2787,11 +2807,19 @@ def test_to_dataframe_w_bqstorage_v1beta1_no_streams(self):
27872807 table = mut .TableReference .from_string ("proj.dset.tbl" ),
27882808 )
27892809
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+
27912813 column_names = ["colA" , "colC" , "colB" ]
27922814 self .assertEqual (list (got ), column_names )
27932815 self .assertTrue (got .empty )
27942816
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+
27952823 @unittest .skipIf (
27962824 bigquery_storage_v1 is None , "Requires `google-cloud-bigquery-storage`"
27972825 )
@@ -3493,7 +3521,10 @@ def test_to_dataframe_concat_categorical_dtype_wo_pyarrow(self):
34933521
34943522 row_iterator = self ._make_one (_mock_client (), api_request , path , schema )
34953523
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 :
34973528 got = row_iterator .to_dataframe (
34983529 dtypes = {
34993530 "col_category" : pandas .core .dtypes .dtypes .CategoricalDtype (
@@ -3522,6 +3553,10 @@ def test_to_dataframe_concat_categorical_dtype_wo_pyarrow(self):
35223553 ["low" , "medium" , "low" , "medium" , "high" , "low" ],
35233554 )
35243555
3556+ self .assertEqual (len (warned ), 1 )
3557+ warning = warned [0 ]
3558+ self .assertTrue ("without pyarrow" in str (warning ))
3559+
35253560
35263561class TestPartitionRange (unittest .TestCase ):
35273562 def _get_target_class (self ):
0 commit comments