@@ -2208,6 +2208,42 @@ def test_to_dataframe_error_if_pandas_is_none(self):
22082208 with self .assertRaises (ValueError ):
22092209 row_iterator .to_dataframe ()
22102210
2211+ @unittest .skipIf (pandas is None , "Requires `pandas`" )
2212+ def test_to_dataframe_max_results_w_bqstorage_warning (self ):
2213+ from google .cloud .bigquery .table import SchemaField
2214+
2215+ schema = [
2216+ SchemaField ("name" , "STRING" , mode = "REQUIRED" ),
2217+ SchemaField ("age" , "INTEGER" , mode = "REQUIRED" ),
2218+ ]
2219+ rows = [
2220+ {"f" : [{"v" : "Phred Phlyntstone" }, {"v" : "32" }]},
2221+ {"f" : [{"v" : "Bharney Rhubble" }, {"v" : "33" }]},
2222+ ]
2223+ path = "/foo"
2224+ api_request = mock .Mock (return_value = {"rows" : rows })
2225+ bqstorage_client = mock .Mock ()
2226+
2227+ row_iterator = self ._make_one (
2228+ client = _mock_client (),
2229+ api_request = api_request ,
2230+ path = path ,
2231+ schema = schema ,
2232+ max_results = 42 ,
2233+ )
2234+
2235+ with warnings .catch_warnings (record = True ) as warned :
2236+ row_iterator .to_dataframe (bqstorage_client = bqstorage_client )
2237+
2238+ matches = [
2239+ warning
2240+ for warning in warned
2241+ if warning .category is UserWarning
2242+ and "cannot use bqstorage_client" in str (warning ).lower ()
2243+ and "tabledata.list" in str (warning )
2244+ ]
2245+ self .assertEqual (len (matches ), 1 , msg = "User warning was not emitted." )
2246+
22112247 @unittest .skipIf (pandas is None , "Requires `pandas`" )
22122248 @unittest .skipIf (
22132249 bigquery_storage_v1beta1 is None , "Requires `google-cloud-bigquery-storage`"
0 commit comments