Skip to content

Commit 0b9f5ed

Browse files
authored
Adds load_table_from_dataframe() to usage docs and changelog and dedents snippets in usage page (googleapis#5501)
1 parent 73e359d commit 0b9f5ed

2 files changed

Lines changed: 83 additions & 6 deletions

File tree

bigquery/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- NUMERIC type support (#5331)
1212
- Add timeline and top-level slot-millis to query statistics. (#5312)
1313
- Add additional statistics to query plan stages. (#5307)
14+
- Add `client.load_table_from_dataframe()` (#5387)
1415

1516
### Documentation
1617

docs/bigquery/usage.rst

Lines changed: 82 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,36 +102,48 @@ Dataset operations
102102
List datasets for the client's project:
103103

104104
.. literalinclude:: snippets.py
105+
:language: python
106+
:dedent: 4
105107
:start-after: [START bigquery_list_datasets]
106108
:end-before: [END bigquery_list_datasets]
107109

108110
Create a new dataset for the client's project:
109111

110112
.. literalinclude:: snippets.py
113+
:language: python
114+
:dedent: 4
111115
:start-after: [START bigquery_create_dataset]
112116
:end-before: [END bigquery_create_dataset]
113117

114118
Refresh metadata for a dataset (to pick up changes made by another client):
115119

116120
.. literalinclude:: snippets.py
121+
:language: python
122+
:dedent: 4
117123
:start-after: [START bigquery_get_dataset]
118124
:end-before: [END bigquery_get_dataset]
119125

120126
Update a property in a dataset's metadata:
121127

122128
.. literalinclude:: snippets.py
129+
:language: python
130+
:dedent: 4
123131
:start-after: [START bigquery_update_dataset_description]
124132
:end-before: [END bigquery_update_dataset_description]
125133

126134
Modify user permissions on a dataset:
127135

128136
.. literalinclude:: snippets.py
137+
:language: python
138+
:dedent: 4
129139
:start-after: [START bigquery_update_dataset_access]
130140
:end-before: [END bigquery_update_dataset_access]
131141

132142
Delete a dataset:
133143

134144
.. literalinclude:: snippets.py
145+
:language: python
146+
:dedent: 4
135147
:start-after: [START bigquery_delete_dataset]
136148
:end-before: [END bigquery_delete_dataset]
137149

@@ -147,60 +159,80 @@ Table operations
147159
List tables for the dataset:
148160

149161
.. literalinclude:: snippets.py
162+
:language: python
163+
:dedent: 4
150164
:start-after: [START bigquery_list_tables]
151165
:end-before: [END bigquery_list_tables]
152166

153167
Create a table:
154168

155169
.. literalinclude:: snippets.py
170+
:language: python
171+
:dedent: 4
156172
:start-after: [START bigquery_create_table]
157173
:end-before: [END bigquery_create_table]
158174

159175
Get a table:
160176

161177
.. literalinclude:: snippets.py
178+
:language: python
179+
:dedent: 4
162180
:start-after: [START bigquery_get_table]
163181
:end-before: [END bigquery_get_table]
164182

165183
Update a property in a table's metadata:
166184

167185
.. literalinclude:: snippets.py
186+
:language: python
187+
:dedent: 4
168188
:start-after: [START bigquery_update_table_description]
169189
:end-before: [END bigquery_update_table_description]
170190

171191
Browse selected rows in a table:
172192

173193
.. literalinclude:: snippets.py
194+
:language: python
195+
:dedent: 4
174196
:start-after: [START bigquery_browse_table]
175197
:end-before: [END bigquery_browse_table]
176198

177199
Insert rows into a table's data:
178200

179201
.. literalinclude:: snippets.py
202+
:language: python
203+
:dedent: 4
180204
:start-after: [START bigquery_table_insert_rows]
181205
:end-before: [END bigquery_table_insert_rows]
182206

183207
Copy a table:
184208

185209
.. literalinclude:: snippets.py
210+
:language: python
211+
:dedent: 4
186212
:start-after: [START bigquery_copy_table]
187213
:end-before: [END bigquery_copy_table]
188214

189215
Extract a table to Google Cloud Storage:
190216

191217
.. literalinclude:: snippets.py
218+
:language: python
219+
:dedent: 4
192220
:start-after: [START bigquery_extract_table]
193221
:end-before: [END bigquery_extract_table]
194222

195223
Delete a table:
196224

197225
.. literalinclude:: snippets.py
226+
:language: python
227+
:dedent: 4
198228
:start-after: [START bigquery_delete_table]
199229
:end-before: [END bigquery_delete_table]
200230

201231
Upload table data from a file:
202232

203233
.. literalinclude:: snippets.py
234+
:language: python
235+
:dedent: 4
204236
:start-after: [START bigquery_load_from_file]
205237
:end-before: [END bigquery_load_from_file]
206238

@@ -213,18 +245,24 @@ See also: `Loading JSON data from Cloud Storage
213245
Load a CSV file from Cloud Storage:
214246

215247
.. literalinclude:: snippets.py
248+
:language: python
249+
:dedent: 4
216250
:start-after: [START bigquery_load_table_gcs_csv]
217251
:end-before: [END bigquery_load_table_gcs_csv]
218252

219253
Load a JSON file from Cloud Storage:
220254

221255
.. literalinclude:: snippets.py
256+
:language: python
257+
:dedent: 4
222258
:start-after: [START bigquery_load_table_gcs_json]
223259
:end-before: [END bigquery_load_table_gcs_json]
224260

225261
Load a Parquet file from Cloud Storage:
226262

227263
.. literalinclude:: snippets.py
264+
:language: python
265+
:dedent: 4
228266
:start-after: [START bigquery_load_table_gcs_parquet]
229267
:end-before: [END bigquery_load_table_gcs_parquet]
230268

@@ -241,33 +279,43 @@ Create a new table, using a customer-managed encryption key from
241279
Cloud KMS to encrypt it.
242280

243281
.. literalinclude:: snippets.py
282+
:language: python
283+
:dedent: 4
244284
:start-after: [START bigquery_create_table_cmek]
245285
:end-before: [END bigquery_create_table_cmek]
246286

247287
Change the key used to encrypt a table.
248288

249289
.. literalinclude:: snippets.py
290+
:language: python
291+
:dedent: 4
250292
:start-after: [START bigquery_update_table_cmek]
251293
:end-before: [END bigquery_update_table_cmek]
252294

253295
Load a file from Cloud Storage, using a customer-managed encryption key from
254296
Cloud KMS for the destination table.
255297

256298
.. literalinclude:: snippets.py
299+
:language: python
300+
:dedent: 4
257301
:start-after: [START bigquery_load_table_gcs_json_cmek]
258302
:end-before: [END bigquery_load_table_gcs_json_cmek]
259303

260304
Copy a table, using a customer-managed encryption key from Cloud KMS for the
261305
destination table.
262306

263307
.. literalinclude:: snippets.py
308+
:language: python
309+
:dedent: 4
264310
:start-after: [START bigquery_copy_table_cmek]
265311
:end-before: [END bigquery_copy_table_cmek]
266312

267313
Write query results to a table, using a customer-managed encryption key from
268314
Cloud KMS for the destination table.
269315

270316
.. literalinclude:: snippets.py
317+
:language: python
318+
:dedent: 4
271319
:start-after: [START bigquery_query_destination_table_cmek]
272320
:end-before: [END bigquery_query_destination_table_cmek]
273321

@@ -281,6 +329,8 @@ Querying data
281329
Run a query and wait for it to finish:
282330

283331
.. literalinclude:: snippets.py
332+
:language: python
333+
:dedent: 4
284334
:start-after: [START bigquery_query]
285335
:end-before: [END bigquery_query]
286336

@@ -289,6 +339,8 @@ Run a dry run query
289339
~~~~~~~~~~~~~~~~~~~
290340

291341
.. literalinclude:: snippets.py
342+
:language: python
343+
:dedent: 4
292344
:start-after: [START bigquery_query_dry_run]
293345
:end-before: [END bigquery_query_dry_run]
294346

@@ -300,8 +352,10 @@ See BigQuery documentation for more information on
300352
`writing query results <https://cloud.google.com/bigquery/docs/writing-results>`_.
301353

302354
.. literalinclude:: snippets.py
303-
:start-after: [START bigquery_query_destination_table]
304-
:end-before: [END bigquery_query_destination_table]
355+
:language: python
356+
:dedent: 4
357+
:start-after: [START bigquery_query_destination_table]
358+
:end-before: [END bigquery_query_destination_table]
305359

306360

307361
Run a query using a named query parameter
@@ -311,12 +365,14 @@ See BigQuery documentation for more information on
311365
`parameterized queries <https://cloud.google.com/bigquery/docs/parameterized-queries>`_.
312366

313367
.. literalinclude:: snippets.py
314-
:start-after: [START bigquery_query_params_named]
315-
:end-before: [END bigquery_query_params_named]
368+
:language: python
369+
:dedent: 4
370+
:start-after: [START bigquery_query_params_named]
371+
:end-before: [END bigquery_query_params_named]
316372

317373

318374
List jobs for a project
319-
~~~~~~~~~~~~~~~~~~~~~~~~~~~
375+
-----------------------
320376

321377
Jobs describe actions performed on data in BigQuery tables:
322378

@@ -326,12 +382,14 @@ Jobs describe actions performed on data in BigQuery tables:
326382
- Copy a table
327383

328384
.. literalinclude:: snippets.py
385+
:language: python
386+
:dedent: 4
329387
:start-after: [START bigquery_list_jobs]
330388
:end-before: [END bigquery_list_jobs]
331389

332390

333391
Using BigQuery with Pandas
334-
~~~~~~~~~~~~~~~~~~~~~~~~~~
392+
--------------------------
335393

336394
As of version 0.29.0, you can use the
337395
:func:`~google.cloud.bigquery.table.RowIterator.to_dataframe` function to
@@ -353,15 +411,33 @@ Alternatively, you can install the BigQuery python client library with
353411
To retrieve query results as a :class:`pandas.DataFrame`:
354412

355413
.. literalinclude:: snippets.py
414+
:language: python
415+
:dedent: 4
356416
:start-after: [START bigquery_query_results_dataframe]
357417
:end-before: [END bigquery_query_results_dataframe]
358418

359419
To retrieve table rows as a :class:`pandas.DataFrame`:
360420

361421
.. literalinclude:: snippets.py
422+
:language: python
423+
:dedent: 4
362424
:start-after: [START bigquery_list_rows_dataframe]
363425
:end-before: [END bigquery_list_rows_dataframe]
364426

427+
As of version 1.3.0, you can use the
428+
:func:`~google.cloud.bigquery.client.Client.load_table_from_dataframe` function
429+
to load data from a :class:`pandas.DataFrame` to a
430+
:class:`~google.cloud.bigquery.table.Table`.
431+
432+
The following example demonstrates how to create a :class:`pandas.DataFrame`
433+
and load it into a new table:
434+
435+
.. literalinclude:: snippets.py
436+
:language: python
437+
:dedent: 4
438+
:start-after: [START bigquery_load_table_dataframe]
439+
:end-before: [END bigquery_load_table_dataframe]
440+
365441
Changelog
366442
---------
367443

0 commit comments

Comments
 (0)