@@ -1100,60 +1100,90 @@ def to_dict(self, orient='dict', into=dict):
1100
1100
else :
1101
1101
raise ValueError ("orient '%s' not understood" % orient )
1102
1102
1103
- def to_gbq (self , destination_table , project_id , chunksize = 10000 ,
1104
- verbose = True , reauth = False , if_exists = 'fail' , private_key = None ):
1105
- """Write a DataFrame to a Google BigQuery table.
1106
-
1107
- The main method a user calls to export pandas DataFrame contents to
1108
- Google BigQuery table.
1103
+ def to_gbq (self , destination_table , project_id , chunksize = None ,
1104
+ verbose = None , reauth = False , if_exists = 'fail' , private_key = None ,
1105
+ auth_local_webserver = False , table_schema = None ):
1106
+ """
1107
+ Write a DataFrame to a Google BigQuery table.
1109
1108
1110
- Google BigQuery API Client Library v2 for Python is used.
1111
- Documentation is available `here
1112
- <https://developers.google.com/api-client-library/python/apis/bigquery/v2>`__
1109
+ This function requires the `pandas-gbq package
1110
+ <https://pandas-gbq.readthedocs.io>`__.
1113
1111
1114
1112
Authentication to the Google BigQuery service is via OAuth 2.0.
1115
1113
1116
- - If "private_key" is not provided:
1114
+ - If ``private_key`` is provided, the library loads the JSON service
1115
+ account credentials and uses those to authenticate.
1117
1116
1118
- By default "application default credentials" are used.
1117
+ - If no ``private_key`` is provided, the library tries `application
1118
+ default credentials`_.
1119
1119
1120
- If default application credentials are not found or are restrictive,
1121
- user account credentials are used. In this case, you will be asked to
1122
- grant permissions for product name 'pandas GBQ'.
1120
+ .. _application default credentials:
1121
+ https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application
1123
1122
1124
- - If "private_key" is provided:
1125
-
1126
- Service account credentials will be used to authenticate.
1123
+ - If application default credentials are not found or cannot be used
1124
+ with BigQuery, the library authenticates with user account
1125
+ credentials. In this case, you will be asked to grant permissions
1126
+ for product name 'pandas GBQ'.
1127
1127
1128
1128
Parameters
1129
1129
----------
1130
- dataframe : DataFrame
1131
- DataFrame to be written
1132
- destination_table : string
1133
- Name of table to be written, in the form 'dataset.tablename'
1130
+ destination_table : str
1131
+ Name of table to be written, in the form 'dataset.tablename'.
1134
1132
project_id : str
1135
1133
Google BigQuery Account project ID.
1136
- chunksize : int (default 10000)
1134
+ chunksize : int, optional
1137
1135
Number of rows to be inserted in each chunk from the dataframe.
1138
- verbose : boolean (default True)
1139
- Show percentage complete
1140
- reauth : boolean (default False)
1136
+ Set to ``None`` to load the whole dataframe at once.
1137
+ reauth : bool, default False
1141
1138
Force Google BigQuery to reauthenticate the user. This is useful
1142
1139
if multiple accounts are used.
1143
- if_exists : {'fail', 'replace', 'append'}, default 'fail'
1144
- 'fail': If table exists, do nothing.
1145
- 'replace': If table exists, drop it, recreate it, and insert data.
1146
- 'append': If table exists, insert data. Create if does not exist.
1147
- private_key : str (optional)
1140
+ if_exists : str, default 'fail'
1141
+ Behavior when the destination table exists. Value can be one of:
1142
+
1143
+ ``'fail'``
1144
+ If table exists, do nothing.
1145
+ ``'replace'``
1146
+ If table exists, drop it, recreate it, and insert data.
1147
+ ``'append'``
1148
+ If table exists, insert data. Create if does not exist.
1149
+ private_key : str, optional
1148
1150
Service account private key in JSON format. Can be file path
1149
1151
or string contents. This is useful for remote server
1150
- authentication (eg. Jupyter/IPython notebook on remote host)
1151
- """
1152
+ authentication (eg. Jupyter/IPython notebook on remote host).
1153
+ auth_local_webserver : bool, default False
1154
+ Use the `local webserver flow`_ instead of the `console flow`_
1155
+ when getting user credentials.
1156
+
1157
+ .. _local webserver flow:
1158
+ http://google-auth-oauthlib.readthedocs.io/en/latest/reference/google_auth_oauthlib.flow.html#google_auth_oauthlib.flow.InstalledAppFlow.run_local_server
1159
+ .. _console flow:
1160
+ http://google-auth-oauthlib.readthedocs.io/en/latest/reference/google_auth_oauthlib.flow.html#google_auth_oauthlib.flow.InstalledAppFlow.run_console
1161
+
1162
+ *New in version 0.2.0 of pandas-gbq*.
1163
+ table_schema : list of dicts, optional
1164
+ List of BigQuery table fields to which according DataFrame
1165
+ columns conform to, e.g. ``[{'name': 'col1', 'type':
1166
+ 'STRING'},...]``. If schema is not provided, it will be
1167
+ generated according to dtypes of DataFrame columns. See
1168
+ BigQuery API documentation on available names of a field.
1169
+
1170
+ *New in version 0.3.1 of pandas-gbq*.
1171
+ verbose : boolean, deprecated
1172
+ *Deprecated in Pandas-GBQ 0.4.0.* Use the `logging module
1173
+ to adjust verbosity instead
1174
+ <https://pandas-gbq.readthedocs.io/en/latest/intro.html#logging>`__.
1152
1175
1176
+ See Also
1177
+ --------
1178
+ pandas_gbq.to_gbq : This function in the pandas-gbq library.
1179
+ pandas.read_gbq : Read a DataFrame from Google BigQuery.
1180
+ """
1153
1181
from pandas .io import gbq
1154
- return gbq .to_gbq (self , destination_table , project_id = project_id ,
1155
- chunksize = chunksize , verbose = verbose , reauth = reauth ,
1156
- if_exists = if_exists , private_key = private_key )
1182
+ return gbq .to_gbq (
1183
+ self , destination_table , project_id , chunksize = chunksize ,
1184
+ verbose = verbose , reauth = reauth , if_exists = if_exists ,
1185
+ private_key = private_key , auth_local_webserver = auth_local_webserver ,
1186
+ table_schema = table_schema )
1157
1187
1158
1188
@classmethod
1159
1189
def from_records (cls , data , index = None , exclude = None , columns = None ,
0 commit comments