33# license that can be found in the LICENSE file.
44
55import copy
6- from datetime import datetime
76import logging
87import re
98import typing
109import warnings
10+ from datetime import datetime
1111
1212import pandas
1313
14- from pandas_gbq .contexts import Context # noqa - backward compatible export
15- from pandas_gbq .contexts import context
16- from pandas_gbq .exceptions import ( # noqa - backward compatible export
14+ import pandas_gbq .schema
15+ import pandas_gbq .schema .pandas_to_bigquery
16+ from pandas_gbq .contexts import ( # noqa: F401
17+ Context , # noqa: F401 - imported solely to support a backwards compatible export
18+ context ,
19+ )
20+ from pandas_gbq .exceptions import ( # noqa: F401 - imported solely to support a backwards compatible export
1721 DatasetCreationError ,
1822 GenericGBQException ,
1923 InvalidColumnOrder ,
2024 InvalidIndexColumn ,
25+ InvalidPageToken , # noqa: F401 - imported solely to support a backwards compatible export
26+ InvalidSchema , # noqa: F401 - imported solely to support a backwards compatible export
2127 NotFoundException ,
28+ QueryTimeout , # noqa: F401 - imported solely to support a backwards compatible export
2229 TableCreationError ,
2330)
24- from pandas_gbq .exceptions import InvalidPageToken # noqa - backward compatible export
25- from pandas_gbq .exceptions import InvalidSchema # noqa - backward compatible export
26- from pandas_gbq .exceptions import QueryTimeout # noqa - backward compatible export
2731from pandas_gbq .features import FEATURES
28- from pandas_gbq .gbq_connector import GbqConnector # noqa - backward compatible export
29- from pandas_gbq . gbq_connector import _get_client # noqa - backward compatible export
30- import pandas_gbq . schema
31- import pandas_gbq . schema . pandas_to_bigquery
32+ from pandas_gbq .gbq_connector import ( # noqa: F401
33+ GbqConnector , # noqa: F401 - imported solely to support a backwards compatible export
34+ _get_client , # noqa: F401 - imported solely to support a backwards compatible export
35+ )
3236
3337logger = logging .getLogger (__name__ )
3438
@@ -40,17 +44,29 @@ def _test_google_api_imports():
4044 raise ImportError ("pandas-gbq requires db-dtypes" ) from ex
4145
4246 try :
43- import db_dtypes # noqa
47+ # db-dtypes does not have type hints nor stubs that mypy uses for type checking.
48+ # This import is solely to test if the package is installed, so we ignore the "unused import" warning.
49+ # Remove this comment and the ignore pragma upon completing:
50+ # https://github.com/googleapis/google-cloud-python/issues/17045
51+ import db_dtypes # type: ignore[import-untyped] # noqa: F401
4452 except ImportError as ex : # pragma: NO COVER
4553 raise ImportError ("pandas-gbq requires db-dtypes" ) from ex
4654
4755 try :
48- import pydata_google_auth # noqa
56+ # pydata-google-auth does not have type hints nor stubs that mypy uses for type checking.
57+ # This import is solely to test if the package is installed, so we ignore the "unused import" warning.
58+ # Remove this comment and the ignore pragma upon completing:
59+ # https://github.com/googleapis/google-cloud-python/issues/17045
60+ import pydata_google_auth # type: ignore[import-untyped] # noqa: F401
4961 except ImportError as ex : # pragma: NO COVER
5062 raise ImportError ("pandas-gbq requires pydata-google-auth" ) from ex
5163
5264 try :
53- from google_auth_oauthlib .flow import InstalledAppFlow # noqa
65+ # google-auth-oauthlib does not have type hints nor stubs that mypy uses for type checking.
66+ # This import is solely to test if the package is installed, so we ignore the "unused import" warning.
67+ # Remove this comment and the ignore pragma upon completing:
68+ # https://github.com/googleapis/google-cloud-python/issues/17045
69+ from google_auth_oauthlib .flow import InstalledAppFlow # type: ignore[import-untyped] # noqa: F401
5470 except ImportError as ex : # pragma: NO COVER
5571 raise ImportError ("pandas-gbq requires google-auth-oauthlib" ) from ex
5672
@@ -686,7 +702,7 @@ def generate_bq_schema(df, default_type="STRING"):
686702 """
687703 # deprecation TimeSeries, #11121
688704 warnings .warn (
689- "generate_bq_schema is deprecated and will be removed in " " a future version" ,
705+ "generate_bq_schema is deprecated and will be removed in a future version" ,
690706 FutureWarning ,
691707 stacklevel = 2 ,
692708 )
@@ -927,9 +943,7 @@ def create(self, dataset_id):
927943 from google .cloud .bigquery import Dataset
928944
929945 if self .exists (dataset_id ):
930- raise DatasetCreationError (
931- "Dataset {0} already " "exists" .format (dataset_id )
932- )
946+ raise DatasetCreationError ("Dataset {0} already exists" .format (dataset_id ))
933947
934948 dataset = Dataset (self ._dataset_ref (dataset_id ))
935949
0 commit comments