@@ -1440,7 +1440,12 @@ def _to_arrow_iterable(self, bqstorage_client=None):
14401440
14411441 # If changing the signature of this method, make sure to apply the same
14421442 # changes to job.QueryJob.to_arrow()
1443- def to_arrow (self , progress_bar_type = None , bqstorage_client = None ):
1443+ def to_arrow (
1444+ self ,
1445+ progress_bar_type = None ,
1446+ bqstorage_client = None ,
1447+ create_bqstorage_client = False ,
1448+ ):
14441449 """[Beta] Create a class:`pyarrow.Table` by loading all pages of a
14451450 table or query.
14461451
@@ -1473,6 +1478,16 @@ def to_arrow(self, progress_bar_type=None, bqstorage_client=None):
14731478
14741479 Reading from a specific partition or snapshot is not
14751480 currently supported by this method.
1481+ create_bqstorage_client (bool):
1482+ **Beta Feature** Optional. If ``True``, create a BigQuery
1483+ Storage API client using the default API settings. The
1484+ BigQuery Storage API is a faster way to fetch rows from
1485+ BigQuery. See the ``bqstorage_client`` parameter for more
1486+ information.
1487+
1488+ This argument does nothing if ``bqstorage_client`` is supplied.
1489+
1490+ ..versionadded:: 1.22.0
14761491
14771492 Returns:
14781493 pyarrow.Table
@@ -1488,6 +1503,9 @@ def to_arrow(self, progress_bar_type=None, bqstorage_client=None):
14881503 if pyarrow is None :
14891504 raise ValueError (_NO_PYARROW_ERROR )
14901505
1506+ if not bqstorage_client and create_bqstorage_client :
1507+ bqstorage_client = self .client ._create_bqstorage_client ()
1508+
14911509 progress_bar = self ._get_progress_bar (progress_bar_type )
14921510
14931511 record_batches = []
@@ -1542,14 +1560,20 @@ def _to_dataframe_iterable(self, bqstorage_client=None, dtypes=None):
15421560
15431561 # If changing the signature of this method, make sure to apply the same
15441562 # changes to job.QueryJob.to_dataframe()
1545- def to_dataframe (self , bqstorage_client = None , dtypes = None , progress_bar_type = None ):
1563+ def to_dataframe (
1564+ self ,
1565+ bqstorage_client = None ,
1566+ dtypes = None ,
1567+ progress_bar_type = None ,
1568+ create_bqstorage_client = False ,
1569+ ):
15461570 """Create a pandas DataFrame by loading all pages of a query.
15471571
15481572 Args:
15491573 bqstorage_client (google.cloud.bigquery_storage_v1beta1.BigQueryStorageClient):
15501574 **Beta Feature** Optional. A BigQuery Storage API client. If
15511575 supplied, use the faster BigQuery Storage API to fetch rows
1552- from BigQuery. This API is a billable API.
1576+ from BigQuery.
15531577
15541578 This method requires the ``pyarrow`` and
15551579 ``google-cloud-bigquery-storage`` libraries.
@@ -1586,6 +1610,16 @@ def to_dataframe(self, bqstorage_client=None, dtypes=None, progress_bar_type=Non
15861610 progress bar as a graphical dialog box.
15871611
15881612 ..versionadded:: 1.11.0
1613+ create_bqstorage_client (bool):
1614+ **Beta Feature** Optional. If ``True``, create a BigQuery
1615+ Storage API client using the default API settings. The
1616+ BigQuery Storage API is a faster way to fetch rows from
1617+ BigQuery. See the ``bqstorage_client`` parameter for more
1618+ information.
1619+
1620+ This argument does nothing if ``bqstorage_client`` is supplied.
1621+
1622+ ..versionadded:: 1.22.0
15891623
15901624 Returns:
15911625 pandas.DataFrame:
@@ -1605,6 +1639,9 @@ def to_dataframe(self, bqstorage_client=None, dtypes=None, progress_bar_type=Non
16051639 if dtypes is None :
16061640 dtypes = {}
16071641
1642+ if not bqstorage_client and create_bqstorage_client :
1643+ bqstorage_client = self .client ._create_bqstorage_client ()
1644+
16081645 if bqstorage_client and self .max_results is not None :
16091646 warnings .warn (
16101647 "Cannot use bqstorage_client if max_results is set, "
@@ -1651,11 +1688,18 @@ class _EmptyRowIterator(object):
16511688 pages = ()
16521689 total_rows = 0
16531690
1654- def to_arrow (self , progress_bar_type = None ):
1691+ def to_arrow (
1692+ self ,
1693+ progress_bar_type = None ,
1694+ bqstorage_client = None ,
1695+ create_bqstorage_client = False ,
1696+ ):
16551697 """[Beta] Create an empty class:`pyarrow.Table`.
16561698
16571699 Args:
16581700 progress_bar_type (Optional[str]): Ignored. Added for compatibility with RowIterator.
1701+ bqstorage_client (Any): Ignored. Added for compatibility with RowIterator.
1702+ create_bqstorage_client (bool): Ignored. Added for compatibility with RowIterator.
16591703
16601704 Returns:
16611705 pyarrow.Table: An empty :class:`pyarrow.Table`.
@@ -1664,13 +1708,20 @@ def to_arrow(self, progress_bar_type=None):
16641708 raise ValueError (_NO_PYARROW_ERROR )
16651709 return pyarrow .Table .from_arrays (())
16661710
1667- def to_dataframe (self , bqstorage_client = None , dtypes = None , progress_bar_type = None ):
1711+ def to_dataframe (
1712+ self ,
1713+ bqstorage_client = None ,
1714+ dtypes = None ,
1715+ progress_bar_type = None ,
1716+ create_bqstorage_client = False ,
1717+ ):
16681718 """Create an empty dataframe.
16691719
16701720 Args:
16711721 bqstorage_client (Any): Ignored. Added for compatibility with RowIterator.
16721722 dtypes (Any): Ignored. Added for compatibility with RowIterator.
16731723 progress_bar_type (Any): Ignored. Added for compatibility with RowIterator.
1724+ create_bqstorage_client (bool): Ignored. Added for compatibility with RowIterator.
16741725
16751726 Returns:
16761727 pandas.DataFrame: An empty :class:`~pandas.DataFrame`.
0 commit comments