Skip to content

Commit

Permalink
Add args from RowIterator.to_dataframe() to QueryJob.to_dataframe()
Browse files Browse the repository at this point in the history
  • Loading branch information
tswast committed Jan 31, 2019
1 parent fd19a75 commit aaf32ce
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions bigquery/google/cloud/bigquery/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -2778,9 +2778,34 @@ def result(self, timeout=None, retry=DEFAULT_RETRY):
dest_table = Table(dest_table_ref, schema=schema)
return self._client.list_rows(dest_table, retry=retry)

def to_dataframe(self):
def to_dataframe(self, bqstorage_client=None, dtypes=None):
"""Return a pandas DataFrame from a QueryJob
Args:
bqstorage_client ( \
google.cloud.bigquery_storage_v1beta1.BigQueryStorageClient \
):
**Alpha Feature** Optional. A BigQuery Storage API client. If
supplied, use the faster BigQuery Storage API to fetch rows
from BigQuery. This API is a billable API.
This method requires the ``fastavro`` and
``google-cloud-bigquery-storage`` libraries.
Reading from a specific partition or snapshot is not
currently supported by this method.
**Caution**: There is a known issue reading small anonymous
query result tables with the BQ Storage API. Write your query
results to a destination table to work around this issue.
dtypes ( \
Map[str, Union[str, pandas.Series.dtype]] \
):
Optional. A dictionary of column names pandas ``dtype``s. The
provided ``dtype`` is used when constructing the series for
the column specified. Otherwise, the default pandas behavior
is used.
Returns:
A :class:`~pandas.DataFrame` populated with row data and column
headers from the query results. The column headers are derived
Expand All @@ -2789,7 +2814,9 @@ def to_dataframe(self):
Raises:
ValueError: If the `pandas` library cannot be imported.
"""
return self.result().to_dataframe()
return self.result().to_dataframe(
bqstorage_client=bqstorage_client, dtypes=dtypes
)

def __iter__(self):
return iter(self.result())
Expand Down

0 comments on commit aaf32ce

Please sign in to comment.