From 2d69758d90e3525a390a4e0685ff2cff397dac1c Mon Sep 17 00:00:00 2001 From: Amit Kumar Date: Fri, 27 Apr 2018 15:59:17 +0100 Subject: [PATCH] remove tqdm import check function and import at top --- pandas_gbq/gbq.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/pandas_gbq/gbq.py b/pandas_gbq/gbq.py index a0bf2ffb..5da85e82 100644 --- a/pandas_gbq/gbq.py +++ b/pandas_gbq/gbq.py @@ -16,6 +16,11 @@ BIGQUERY_INSTALLED_VERSION = None SHOW_VERBOSE_DEPRECATION = False +try: + import tqdm # noqa +except ImportError: + tqdm = None + def _check_google_client_version(): global BIGQUERY_INSTALLED_VERSION, SHOW_VERBOSE_DEPRECATION @@ -573,9 +578,8 @@ def load_data( chunks = load.load_chunks(self.client, dataframe, dataset_id, table_id, chunksize=chunksize, schema=schema) - if progress_bar and self._check_if_tqdm_exists(): - from tqdm import tqdm - chunks = tqdm(chunks) + if progress_bar and tqdm: + chunks = tqdm.tqdm(chunks) for remaining_rows in chunks: logger.info("\rLoad is {0}% Complete".format( ((total_rows - remaining_rows) * 100) / total_rows)) @@ -584,13 +588,6 @@ def load_data( logger.info("\n") - def _check_if_tqdm_exists(self): - try: - import tqdm # noqa - return True - except ImportError: - return False - def schema(self, dataset_id, table_id): """Retrieve the schema of the table