Skip to content

TPY: Add Types to gbq.py #30632

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 29 additions & 24 deletions pandas/io/gbq.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
""" Google BigQuery support """
from typing import TYPE_CHECKING, Any, 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
Expand All @@ -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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this explicitly need to be a List or does Sequence work as well?

Copy link
Member Author

@alimcmaster1 alimcmaster1 Jan 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh good point - tried the other basic sequence types and they throw. Since it's used to retrieve columns from a DataFrame. Like df[col_order]. So think List it is!

reauth: bool = False,
auth_local_webserver: bool = False,
dialect: Optional[str] = None,
location: Optional[str] = None,
configuration: Optional[Dict[str, Any]] = 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.

Expand Down Expand Up @@ -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:
Expand All @@ -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,
Expand Down