|
35 | 35 | "execution_count": 2, |
36 | 36 | "id": "ca22f059", |
37 | 37 | "metadata": {}, |
38 | | - "outputs": [], |
| 38 | + "outputs": [ |
| 39 | + { |
| 40 | + "name": "stderr", |
| 41 | + "output_type": "stream", |
| 42 | + "text": [ |
| 43 | + "/usr/local/google/home/shuowei/src/python-bigquery-dataframes/venv/lib/python3.10/site-packages/google/api_core/_python_version_support.py:266: FutureWarning: You are using a Python version (3.10.15) which Google will stop supporting in new releases of google.api_core once it reaches its end of life (2026-10-04). Please upgrade to the latest Python version, or at least Python 3.11, to continue receiving updates for google.api_core past that date.\n", |
| 44 | + " warnings.warn(message, FutureWarning)\n" |
| 45 | + ] |
| 46 | + } |
| 47 | + ], |
39 | 48 | "source": [ |
40 | 49 | "import bigframes.pandas as bpd" |
41 | 50 | ] |
|
142 | 151 | { |
143 | 152 | "data": { |
144 | 153 | "application/vnd.jupyter.widget-view+json": { |
145 | | - "model_id": "aafd4f912b5f42e0896aa5f0c2c62620", |
| 154 | + "model_id": "47795eaa10f149aeb99574232c0936eb", |
146 | 155 | "version_major": 2, |
147 | | - "version_minor": 0 |
| 156 | + "version_minor": 1 |
148 | 157 | }, |
149 | 158 | "text/plain": [ |
150 | 159 | "TableWidget(page_size=10, row_count=5552452, table_html='<table border=\"1\" class=\"dataframe table table-stripe…" |
|
205 | 214 | { |
206 | 215 | "data": { |
207 | 216 | "application/vnd.jupyter.widget-view+json": { |
208 | | - "model_id": "5ec0ad9f11874d4f9d8edbc903ee7b5d", |
| 217 | + "model_id": "8354ce0f82d3495a9b630dfc362f73ee", |
209 | 218 | "version_major": 2, |
210 | | - "version_minor": 0 |
| 219 | + "version_minor": 1 |
211 | 220 | }, |
212 | 221 | "text/plain": [ |
213 | 222 | "TableWidget(page_size=10, row_count=5552452, table_html='<table border=\"1\" class=\"dataframe table table-stripe…" |
214 | 223 | ] |
215 | 224 | }, |
| 225 | + "execution_count": 7, |
216 | 226 | "metadata": {}, |
217 | | - "output_type": "display_data" |
| 227 | + "output_type": "execute_result" |
218 | 228 | } |
219 | 229 | ], |
220 | 230 | "source": [ |
|
283 | 293 | { |
284 | 294 | "data": { |
285 | 295 | "text/html": [ |
286 | | - "✅ Completed. \n", |
287 | | - " Query processed 171.4 MB in a moment of slot time.\n", |
| 296 | + "\n", |
| 297 | + " Query started with request ID bigframes-dev:US.c45952fb-01b4-409c-9da4-f7c5bfc0d47d.<details><summary>SQL</summary><pre>SELECT\n", |
| 298 | + "`state` AS `state`,\n", |
| 299 | + "`gender` AS `gender`,\n", |
| 300 | + "`year` AS `year`,\n", |
| 301 | + "`name` AS `name`,\n", |
| 302 | + "`number` AS `number`\n", |
| 303 | + "FROM\n", |
| 304 | + "(SELECT\n", |
| 305 | + " *\n", |
| 306 | + "FROM (\n", |
| 307 | + " SELECT\n", |
| 308 | + " `state`,\n", |
| 309 | + " `gender`,\n", |
| 310 | + " `year`,\n", |
| 311 | + " `name`,\n", |
| 312 | + " `number`\n", |
| 313 | + " FROM `bigquery-public-data.usa_names.usa_1910_2013` FOR SYSTEM_TIME AS OF TIMESTAMP('2025-10-30T21:48:48.979701+00:00')\n", |
| 314 | + ") AS `t0`)\n", |
| 315 | + "ORDER BY `name` ASC NULLS LAST ,`year` ASC NULLS LAST ,`state` ASC NULLS LAST\n", |
| 316 | + "LIMIT 5</pre></details>\n", |
288 | 317 | " " |
289 | 318 | ], |
290 | 319 | "text/plain": [ |
|
304 | 333 | { |
305 | 334 | "data": { |
306 | 335 | "application/vnd.jupyter.widget-view+json": { |
307 | | - "model_id": "651b5aac958c408183775152c2573a03", |
| 336 | + "model_id": "59461286a17d4a42b6be6d9d9c7bf7e3", |
308 | 337 | "version_major": 2, |
309 | | - "version_minor": 0 |
| 338 | + "version_minor": 1 |
310 | 339 | }, |
311 | 340 | "text/plain": [ |
312 | 341 | "TableWidget(page_size=10, row_count=5, table_html='<table border=\"1\" class=\"dataframe table table-striped tabl…" |
313 | 342 | ] |
314 | 343 | }, |
| 344 | + "execution_count": 9, |
315 | 345 | "metadata": {}, |
316 | | - "output_type": "display_data" |
| 346 | + "output_type": "execute_result" |
317 | 347 | } |
318 | 348 | ], |
319 | 349 | "source": [ |
|
323 | 353 | "print(f\"Small dataset pages: {math.ceil(small_widget.row_count / small_widget.page_size)}\")\n", |
324 | 354 | "small_widget" |
325 | 355 | ] |
| 356 | + }, |
| 357 | + { |
| 358 | + "cell_type": "markdown", |
| 359 | + "id": "added-cell-2", |
| 360 | + "metadata": {}, |
| 361 | + "source": [ |
| 362 | + "### Displaying Generative AI results containing JSON\n", |
| 363 | + "The `AI.GENERATE` function in BigQuery returns results in a JSON column. While BigQuery's JSON type is not natively supported by the underlying Arrow `to_pandas_batches()` method used in anywidget mode ([Apache Arrow issue #45262](https://github.com/apache/arrow/issues/45262)), BigQuery Dataframes automatically converts JSON columns to strings for display. This allows you to view the results of generative AI functions seamlessly." |
| 364 | + ] |
| 365 | + }, |
| 366 | + { |
| 367 | + "cell_type": "code", |
| 368 | + "execution_count": 10, |
| 369 | + "id": "added-cell-1", |
| 370 | + "metadata": {}, |
| 371 | + "outputs": [ |
| 372 | + { |
| 373 | + "data": { |
| 374 | + "text/html": [ |
| 375 | + "✅ Completed. \n", |
| 376 | + " Query processed 85.9 kB in 14 seconds of slot time.\n", |
| 377 | + " " |
| 378 | + ], |
| 379 | + "text/plain": [ |
| 380 | + "<IPython.core.display.HTML object>" |
| 381 | + ] |
| 382 | + }, |
| 383 | + "metadata": {}, |
| 384 | + "output_type": "display_data" |
| 385 | + }, |
| 386 | + { |
| 387 | + "name": "stderr", |
| 388 | + "output_type": "stream", |
| 389 | + "text": [ |
| 390 | + "/usr/local/google/home/shuowei/src/python-bigquery-dataframes/bigframes/dtypes.py:969: JSONDtypeWarning: JSON columns will be represented as pandas.ArrowDtype(pyarrow.json_())\n", |
| 391 | + "instead of using `db_dtypes` in the future when available in pandas\n", |
| 392 | + "(https://github.com/pandas-dev/pandas/issues/60958) and pyarrow.\n", |
| 393 | + " warnings.warn(msg, bigframes.exceptions.JSONDtypeWarning)\n" |
| 394 | + ] |
| 395 | + }, |
| 396 | + { |
| 397 | + "data": { |
| 398 | + "text/html": [ |
| 399 | + "✅ Completed. " |
| 400 | + ], |
| 401 | + "text/plain": [ |
| 402 | + "<IPython.core.display.HTML object>" |
| 403 | + ] |
| 404 | + }, |
| 405 | + "metadata": {}, |
| 406 | + "output_type": "display_data" |
| 407 | + }, |
| 408 | + { |
| 409 | + "data": { |
| 410 | + "application/vnd.jupyter.widget-view+json": { |
| 411 | + "model_id": "d1794b42579542a8980bd158e521bd3e", |
| 412 | + "version_major": 2, |
| 413 | + "version_minor": 1 |
| 414 | + }, |
| 415 | + "text/plain": [ |
| 416 | + "TableWidget(page_size=10, row_count=5, table_html='<table border=\"1\" class=\"dataframe table table-striped tabl…" |
| 417 | + ] |
| 418 | + }, |
| 419 | + "metadata": {}, |
| 420 | + "output_type": "display_data" |
| 421 | + }, |
| 422 | + { |
| 423 | + "data": { |
| 424 | + "text/html": [], |
| 425 | + "text/plain": [ |
| 426 | + "Computation deferred. Computation will process 0 Bytes" |
| 427 | + ] |
| 428 | + }, |
| 429 | + "execution_count": 10, |
| 430 | + "metadata": {}, |
| 431 | + "output_type": "execute_result" |
| 432 | + } |
| 433 | + ], |
| 434 | + "source": [ |
| 435 | + "bpd._read_gbq_colab(\"\"\"\n", |
| 436 | + " SELECT\n", |
| 437 | + " AI.GENERATE(\n", |
| 438 | + " prompt=>(\\\"Extract the values.\\\", OBJ.GET_ACCESS_URL(OBJ.FETCH_METADATA(OBJ.MAKE_REF(gcs_path, \\\"us.conn\\\")), \\\"r\\\")),\n", |
| 439 | + " connection_id=>\\\"bigframes-dev.us.bigframes-default-connection\\\",\n", |
| 440 | + " output_schema=>\\\"publication_date string, class_international string, application_number string, filing_date string\\\") AS result,\n", |
| 441 | + " *\n", |
| 442 | + " FROM `bigquery-public-data.labeled_patents.extracted_data`\n", |
| 443 | + " LIMIT 5;\n", |
| 444 | + "\"\"\")" |
| 445 | + ] |
326 | 446 | } |
327 | 447 | ], |
328 | 448 | "metadata": { |
329 | 449 | "kernelspec": { |
330 | | - "display_name": "3.10.18", |
| 450 | + "display_name": "venv", |
331 | 451 | "language": "python", |
332 | 452 | "name": "python3" |
333 | 453 | }, |
|
341 | 461 | "name": "python", |
342 | 462 | "nbconvert_exporter": "python", |
343 | 463 | "pygments_lexer": "ipython3", |
344 | | - "version": "3.10.18" |
| 464 | + "version": "3.10.15" |
345 | 465 | } |
346 | 466 | }, |
347 | 467 | "nbformat": 4, |
|
0 commit comments