|
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": "473b016aa6b24c86aafc6372352e822d", |
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": "339279cc312e4e7fb67923e4e6ad7779", |
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": [ |
|
304 | 314 | { |
305 | 315 | "data": { |
306 | 316 | "application/vnd.jupyter.widget-view+json": { |
307 | | - "model_id": "651b5aac958c408183775152c2573a03", |
| 317 | + "model_id": "8ff1f64c44304da0944eadbd0fb3981d", |
308 | 318 | "version_major": 2, |
309 | | - "version_minor": 0 |
| 319 | + "version_minor": 1 |
310 | 320 | }, |
311 | 321 | "text/plain": [ |
312 | 322 | "TableWidget(page_size=10, row_count=5, table_html='<table border=\"1\" class=\"dataframe table table-striped tabl…" |
313 | 323 | ] |
314 | 324 | }, |
| 325 | + "execution_count": 9, |
315 | 326 | "metadata": {}, |
316 | | - "output_type": "display_data" |
| 327 | + "output_type": "execute_result" |
317 | 328 | } |
318 | 329 | ], |
319 | 330 | "source": [ |
|
323 | 334 | "print(f\"Small dataset pages: {math.ceil(small_widget.row_count / small_widget.page_size)}\")\n", |
324 | 335 | "small_widget" |
325 | 336 | ] |
| 337 | + }, |
| 338 | + { |
| 339 | + "cell_type": "markdown", |
| 340 | + "id": "added-cell-2", |
| 341 | + "metadata": {}, |
| 342 | + "source": [ |
| 343 | + "### Displaying Generative AI results containing JSON\n", |
| 344 | + "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." |
| 345 | + ] |
| 346 | + }, |
| 347 | + { |
| 348 | + "cell_type": "code", |
| 349 | + "execution_count": 10, |
| 350 | + "id": "added-cell-1", |
| 351 | + "metadata": {}, |
| 352 | + "outputs": [ |
| 353 | + { |
| 354 | + "data": { |
| 355 | + "text/html": [ |
| 356 | + "✅ Completed. \n", |
| 357 | + " Query processed 85.9 kB in 15 seconds of slot time.\n", |
| 358 | + " " |
| 359 | + ], |
| 360 | + "text/plain": [ |
| 361 | + "<IPython.core.display.HTML object>" |
| 362 | + ] |
| 363 | + }, |
| 364 | + "metadata": {}, |
| 365 | + "output_type": "display_data" |
| 366 | + }, |
| 367 | + { |
| 368 | + "name": "stderr", |
| 369 | + "output_type": "stream", |
| 370 | + "text": [ |
| 371 | + "/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", |
| 372 | + "instead of using `db_dtypes` in the future when available in pandas\n", |
| 373 | + "(https://github.com/pandas-dev/pandas/issues/60958) and pyarrow.\n", |
| 374 | + " warnings.warn(msg, bigframes.exceptions.JSONDtypeWarning)\n" |
| 375 | + ] |
| 376 | + }, |
| 377 | + { |
| 378 | + "data": { |
| 379 | + "text/html": [ |
| 380 | + "✅ Completed. " |
| 381 | + ], |
| 382 | + "text/plain": [ |
| 383 | + "<IPython.core.display.HTML object>" |
| 384 | + ] |
| 385 | + }, |
| 386 | + "metadata": {}, |
| 387 | + "output_type": "display_data" |
| 388 | + }, |
| 389 | + { |
| 390 | + "data": { |
| 391 | + "application/vnd.jupyter.widget-view+json": { |
| 392 | + "model_id": "a6d61e48cca642b7a57e6431359b4cc4", |
| 393 | + "version_major": 2, |
| 394 | + "version_minor": 1 |
| 395 | + }, |
| 396 | + "text/plain": [ |
| 397 | + "TableWidget(page_size=10, row_count=5, table_html='<table border=\"1\" class=\"dataframe table table-striped tabl…" |
| 398 | + ] |
| 399 | + }, |
| 400 | + "metadata": {}, |
| 401 | + "output_type": "display_data" |
| 402 | + }, |
| 403 | + { |
| 404 | + "data": { |
| 405 | + "text/html": [], |
| 406 | + "text/plain": [ |
| 407 | + "Computation deferred. Computation will process 0 Bytes" |
| 408 | + ] |
| 409 | + }, |
| 410 | + "execution_count": 10, |
| 411 | + "metadata": {}, |
| 412 | + "output_type": "execute_result" |
| 413 | + } |
| 414 | + ], |
| 415 | + "source": [ |
| 416 | + "bpd._read_gbq_colab(\"\"\"\n", |
| 417 | + " SELECT\n", |
| 418 | + " AI.GENERATE(\n", |
| 419 | + " prompt=>(\\\"Extract the values.\\\", OBJ.GET_ACCESS_URL(OBJ.FETCH_METADATA(OBJ.MAKE_REF(gcs_path, \\\"us.conn\\\")), \\\"r\\\")),\n", |
| 420 | + " connection_id=>\\\"bigframes-dev.us.bigframes-default-connection\\\",\n", |
| 421 | + " output_schema=>\\\"publication_date string, class_international string, application_number string, filing_date string\\\") AS result,\n", |
| 422 | + " *\n", |
| 423 | + " FROM `bigquery-public-data.labeled_patents.extracted_data`\n", |
| 424 | + " LIMIT 5;\n", |
| 425 | + "\"\"\")" |
| 426 | + ] |
326 | 427 | } |
327 | 428 | ], |
328 | 429 | "metadata": { |
|
0 commit comments