From d8caca9e87c994d167c722fa2b0c27c7a653d7fe Mon Sep 17 00:00:00 2001 From: alimcmaster1 Date: Fri, 3 Jan 2020 00:27:20 +0000 Subject: [PATCH 1/3] Add type hints to gbq --- pandas/io/gbq.py | 53 ++++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/pandas/io/gbq.py b/pandas/io/gbq.py index d9711f4f4626a..abd46ba926aea 100644 --- a/pandas/io/gbq.py +++ b/pandas/io/gbq.py @@ -1,6 +1,11 @@ """ Google BigQuery support """ +from typing import TYPE_CHECKING, Dict, List, Optional, Union + from pandas.compat._optional import import_optional_dependency +if TYPE_CHECKING: + from pandas import DataFrame + def _try_import(): # since pandas is a dependency of pandas-gbq @@ -14,21 +19,21 @@ def _try_import(): def read_gbq( - query, - project_id=None, - index_col=None, - col_order=None, - reauth=False, - auth_local_webserver=False, - dialect=None, - location=None, - configuration=None, + query: str, + project_id: Optional[str] = None, + index_col: Optional[str] = None, + col_order: Optional[List[str]] = None, + reauth: bool = False, + auth_local_webserver: bool = False, + dialect: Optional[str] = None, + location: Optional[str] = None, + configuration: Optional[Dict] = None, credentials=None, - use_bqstorage_api=None, + use_bqstorage_api: Optional[bool] = None, private_key=None, verbose=None, - progress_bar_type=None, -): + progress_bar_type: Optional[str] = None, +) -> "DataFrame": """ Load data from Google BigQuery. @@ -157,7 +162,7 @@ def read_gbq( """ pandas_gbq = _try_import() - kwargs = {} + kwargs: Dict[str, Union[str, bool]] = {} # START: new kwargs. Don't populate unless explicitly set. if use_bqstorage_api is not None: @@ -183,20 +188,20 @@ def read_gbq( def to_gbq( - dataframe, - destination_table, - project_id=None, - chunksize=None, - reauth=False, - if_exists="fail", - auth_local_webserver=False, - table_schema=None, - location=None, - progress_bar=True, + dataframe: "DataFrame", + destination_table: str, + project_id: Optional[str] = None, + chunksize: Optional[int] = None, + reauth: bool = False, + if_exists: str = "fail", + auth_local_webserver: bool = False, + table_schema: Optional[List[Dict[str, str]]] = None, + location: Optional[str] = None, + progress_bar: bool = True, credentials=None, verbose=None, private_key=None, -): +) -> None: pandas_gbq = _try_import() pandas_gbq.to_gbq( dataframe, From e3c5e9328b8b56ffd491b605daed76c3179f848b Mon Sep 17 00:00:00 2001 From: alimcmaster1 Date: Fri, 3 Jan 2020 00:30:38 +0000 Subject: [PATCH 2/3] run black --- pandas/io/gbq.py | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/pandas/io/gbq.py b/pandas/io/gbq.py index abd46ba926aea..de77ada4fe73a 100644 --- a/pandas/io/gbq.py +++ b/pandas/io/gbq.py @@ -19,20 +19,20 @@ def _try_import(): def read_gbq( - query: str, - project_id: Optional[str] = None, - index_col: Optional[str] = None, - col_order: Optional[List[str]] = None, - reauth: bool = False, - auth_local_webserver: bool = False, - dialect: Optional[str] = None, - location: Optional[str] = None, - configuration: Optional[Dict] = None, + query: str, + project_id: Optional[str] = None, + index_col: Optional[str] = None, + col_order: Optional[List[str]] = None, + reauth: bool = False, + auth_local_webserver: bool = False, + dialect: Optional[str] = None, + location: Optional[str] = None, + configuration: Optional[Dict] = None, credentials=None, - use_bqstorage_api: Optional[bool] = None, + use_bqstorage_api: Optional[bool] = None, private_key=None, verbose=None, - progress_bar_type: Optional[str] = None, + progress_bar_type: Optional[str] = None, ) -> "DataFrame": """ Load data from Google BigQuery. @@ -188,16 +188,16 @@ def read_gbq( def to_gbq( - dataframe: "DataFrame", - destination_table: str, - project_id: Optional[str] = None, - chunksize: Optional[int] = None, - reauth: bool = False, - if_exists: str = "fail", - auth_local_webserver: bool = False, - table_schema: Optional[List[Dict[str, str]]] = None, - location: Optional[str] = None, - progress_bar: bool = True, + dataframe: "DataFrame", + destination_table: str, + project_id: Optional[str] = None, + chunksize: Optional[int] = None, + reauth: bool = False, + if_exists: str = "fail", + auth_local_webserver: bool = False, + table_schema: Optional[List[Dict[str, str]]] = None, + location: Optional[str] = None, + progress_bar: bool = True, credentials=None, verbose=None, private_key=None, From 1504dee3602e0ef598879f4df9703a0ac57afca7 Mon Sep 17 00:00:00 2001 From: alimcmaster1 Date: Sat, 4 Jan 2020 16:12:28 +0000 Subject: [PATCH 3/3] Add Dict SubTypes --- pandas/io/gbq.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/io/gbq.py b/pandas/io/gbq.py index de77ada4fe73a..69ebc470fba6f 100644 --- a/pandas/io/gbq.py +++ b/pandas/io/gbq.py @@ -1,5 +1,5 @@ """ Google BigQuery support """ -from typing import TYPE_CHECKING, Dict, List, Optional, Union +from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union from pandas.compat._optional import import_optional_dependency @@ -27,7 +27,7 @@ def read_gbq( auth_local_webserver: bool = False, dialect: Optional[str] = None, location: Optional[str] = None, - configuration: Optional[Dict] = None, + configuration: Optional[Dict[str, Any]] = None, credentials=None, use_bqstorage_api: Optional[bool] = None, private_key=None,