|
16 | 16 | BIGQUERY_INSTALLED_VERSION = None
|
17 | 17 | SHOW_VERBOSE_DEPRECATION = False
|
18 | 18 |
|
| 19 | +try: |
| 20 | + import tqdm # noqa |
| 21 | +except ImportError: |
| 22 | + tqdm = None |
| 23 | + |
19 | 24 |
|
20 | 25 | def _check_google_client_version():
|
21 | 26 | global BIGQUERY_INSTALLED_VERSION, SHOW_VERBOSE_DEPRECATION
|
@@ -563,16 +568,19 @@ def run_query(self, query, **kwargs):
|
563 | 568 |
|
564 | 569 | def load_data(
|
565 | 570 | self, dataframe, dataset_id, table_id, chunksize=None,
|
566 |
| - schema=None): |
| 571 | + schema=None, progress_bar=True): |
567 | 572 | from pandas_gbq import load
|
568 | 573 |
|
569 | 574 | total_rows = len(dataframe)
|
570 | 575 | logger.info("\n\n")
|
571 | 576 |
|
572 | 577 | try:
|
573 |
| - for remaining_rows in load.load_chunks( |
574 |
| - self.client, dataframe, dataset_id, table_id, |
575 |
| - chunksize=chunksize, schema=schema): |
| 578 | + chunks = load.load_chunks(self.client, dataframe, dataset_id, |
| 579 | + table_id, chunksize=chunksize, |
| 580 | + schema=schema) |
| 581 | + if progress_bar and tqdm: |
| 582 | + chunks = tqdm.tqdm(chunks) |
| 583 | + for remaining_rows in chunks: |
576 | 584 | logger.info("\rLoad is {0}% Complete".format(
|
577 | 585 | ((total_rows - remaining_rows) * 100) / total_rows))
|
578 | 586 | except self.http_error as ex:
|
@@ -870,7 +878,7 @@ def read_gbq(query, project_id=None, index_col=None, col_order=None,
|
870 | 878 |
|
871 | 879 | def to_gbq(dataframe, destination_table, project_id=None, chunksize=None,
|
872 | 880 | verbose=None, reauth=False, if_exists='fail', private_key=None,
|
873 |
| - auth_local_webserver=False, table_schema=None): |
| 881 | + auth_local_webserver=False, table_schema=None, progress_bar=True): |
874 | 882 | """Write a DataFrame to a Google BigQuery table.
|
875 | 883 |
|
876 | 884 | The main method a user calls to export pandas DataFrame contents to
|
@@ -935,6 +943,8 @@ def to_gbq(dataframe, destination_table, project_id=None, chunksize=None,
|
935 | 943 | names of a field.
|
936 | 944 | .. versionadded:: 0.3.1
|
937 | 945 | verbose : None, deprecated
|
| 946 | + progress_bar : boolean, True by default. It uses the library `tqdm` to show |
| 947 | + the progress bar for the upload, chunk by chunk. |
938 | 948 | """
|
939 | 949 |
|
940 | 950 | _test_google_api_imports()
|
@@ -987,7 +997,7 @@ def to_gbq(dataframe, destination_table, project_id=None, chunksize=None,
|
987 | 997 |
|
988 | 998 | connector.load_data(
|
989 | 999 | dataframe, dataset_id, table_id, chunksize=chunksize,
|
990 |
| - schema=table_schema) |
| 1000 | + schema=table_schema, progress_bar=progress_bar) |
991 | 1001 |
|
992 | 1002 |
|
993 | 1003 | def generate_bq_schema(df, default_type='STRING'):
|
|
0 commit comments