|
35 | 35 | "execution_count": 2, |
36 | 36 | "id": "ca22f059", |
37 | 37 | "metadata": {}, |
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 | | - ], |
| 38 | + "outputs": [], |
48 | 39 | "source": [ |
49 | 40 | "import bigframes.pandas as bpd" |
50 | 41 | ] |
|
151 | 142 | { |
152 | 143 | "data": { |
153 | 144 | "application/vnd.jupyter.widget-view+json": { |
154 | | - "model_id": "47795eaa10f149aeb99574232c0936eb", |
| 145 | + "model_id": "e2e84120b65f4a6d8bff7c7bfbf813e8", |
155 | 146 | "version_major": 2, |
156 | 147 | "version_minor": 1 |
157 | 148 | }, |
|
214 | 205 | { |
215 | 206 | "data": { |
216 | 207 | "application/vnd.jupyter.widget-view+json": { |
217 | | - "model_id": "8354ce0f82d3495a9b630dfc362f73ee", |
| 208 | + "model_id": "fc58c5471b8f444b85e35dd5b93a17ca", |
218 | 209 | "version_major": 2, |
219 | 210 | "version_minor": 1 |
220 | 211 | }, |
|
293 | 284 | { |
294 | 285 | "data": { |
295 | 286 | "text/html": [ |
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", |
| 287 | + "✅ Completed. \n", |
| 288 | + " Query processed 171.4 MB in 2 seconds of slot time.\n", |
317 | 289 | " " |
318 | 290 | ], |
319 | 291 | "text/plain": [ |
|
333 | 305 | { |
334 | 306 | "data": { |
335 | 307 | "application/vnd.jupyter.widget-view+json": { |
336 | | - "model_id": "59461286a17d4a42b6be6d9d9c7bf7e3", |
| 308 | + "model_id": "16ef1baae8934457a4d9e032262cac54", |
337 | 309 | "version_major": 2, |
338 | 310 | "version_minor": 1 |
339 | 311 | }, |
|
373 | 345 | "data": { |
374 | 346 | "text/html": [ |
375 | 347 | "✅ Completed. \n", |
376 | | - " Query processed 85.9 kB in 14 seconds of slot time.\n", |
| 348 | + " Query processed 85.9 kB in 16 seconds of slot time.\n", |
377 | 349 | " " |
378 | 350 | ], |
379 | 351 | "text/plain": [ |
|
387 | 359 | "name": "stderr", |
388 | 360 | "output_type": "stream", |
389 | 361 | "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", |
| 362 | + "/usr/local/google/home/shuowei/src/python-bigquery-dataframes/bigframes/dtypes.py:987: JSONDtypeWarning: JSON columns will be represented as pandas.ArrowDtype(pyarrow.json_())\n", |
391 | 363 | "instead of using `db_dtypes` in the future when available in pandas\n", |
392 | 364 | "(https://github.com/pandas-dev/pandas/issues/60958) and pyarrow.\n", |
393 | 365 | " warnings.warn(msg, bigframes.exceptions.JSONDtypeWarning)\n" |
|
408 | 380 | { |
409 | 381 | "data": { |
410 | 382 | "application/vnd.jupyter.widget-view+json": { |
411 | | - "model_id": "d1794b42579542a8980bd158e521bd3e", |
| 383 | + "model_id": "42d656c30fc34855a8fa5e398de412eb", |
412 | 384 | "version_major": 2, |
413 | 385 | "version_minor": 1 |
414 | 386 | }, |
|
443 | 415 | " LIMIT 5;\n", |
444 | 416 | "\"\"\")" |
445 | 417 | ] |
| 418 | + }, |
| 419 | + { |
| 420 | + "cell_type": "markdown", |
| 421 | + "id": "multi-index-display-markdown", |
| 422 | + "metadata": {}, |
| 423 | + "source": [ |
| 424 | + "## Display Multi-Index DataFrame in anywidget mode\n", |
| 425 | + "This section demonstrates how BigFrames can display a DataFrame with multiple levels of indexing (a \"multi-index\") when using the `anywidget` display mode." |
| 426 | + ] |
| 427 | + }, |
| 428 | + { |
| 429 | + "cell_type": "code", |
| 430 | + "execution_count": 11, |
| 431 | + "id": "ad7482aa", |
| 432 | + "metadata": {}, |
| 433 | + "outputs": [ |
| 434 | + { |
| 435 | + "name": "stderr", |
| 436 | + "output_type": "stream", |
| 437 | + "text": [ |
| 438 | + "/usr/local/google/home/shuowei/src/python-bigquery-dataframes/bigframes/session/_io/bigquery/read_gbq_table.py:483: DefaultIndexWarning: Table 'bigquery-public-data.pypi.file_downloads' is clustered and/or\n", |
| 439 | + "partitioned, but BigQuery DataFrames was not able to find a suitable\n", |
| 440 | + "index. To avoid this warning, set at least one of: `index_col` or\n", |
| 441 | + "`filters`.\n", |
| 442 | + " warnings.warn(msg, category=bfe.DefaultIndexWarning)\n" |
| 443 | + ] |
| 444 | + }, |
| 445 | + { |
| 446 | + "data": { |
| 447 | + "text/html": [ |
| 448 | + "✅ Completed. \n", |
| 449 | + " Query processed 469.9 GB in 55 minutes of slot time. [<a target=\"_blank\" href=\"https://console.cloud.google.com/bigquery?project=bigframes-dev&j=bq:US:27cb1a99-ccf8-4237-b5a6-65cc1a63f6ee&page=queryresults\">Job bigframes-dev:US.27cb1a99-ccf8-4237-b5a6-65cc1a63f6ee details</a>]\n", |
| 450 | + " " |
| 451 | + ], |
| 452 | + "text/plain": [ |
| 453 | + "<IPython.core.display.HTML object>" |
| 454 | + ] |
| 455 | + }, |
| 456 | + "metadata": {}, |
| 457 | + "output_type": "display_data" |
| 458 | + }, |
| 459 | + { |
| 460 | + "data": { |
| 461 | + "text/html": [ |
| 462 | + "✅ Completed. \n", |
| 463 | + " Query processed 110.6 MB in 6 seconds of slot time. [<a target=\"_blank\" href=\"https://console.cloud.google.com/bigquery?project=bigframes-dev&j=bq:US:job_Fu0VQ9m67G-hhsbXQne-UAqqJddU&page=queryresults\">Job bigframes-dev:US.job_Fu0VQ9m67G-hhsbXQne-UAqqJddU details</a>]\n", |
| 464 | + " " |
| 465 | + ], |
| 466 | + "text/plain": [ |
| 467 | + "<IPython.core.display.HTML object>" |
| 468 | + ] |
| 469 | + }, |
| 470 | + "metadata": {}, |
| 471 | + "output_type": "display_data" |
| 472 | + }, |
| 473 | + { |
| 474 | + "data": { |
| 475 | + "application/vnd.jupyter.widget-view+json": { |
| 476 | + "model_id": "e11b0c862f8d45b5aa68487678d1d2d9", |
| 477 | + "version_major": 2, |
| 478 | + "version_minor": 1 |
| 479 | + }, |
| 480 | + "text/plain": [ |
| 481 | + "TableWidget(page_size=10, row_count=3534819, table_html='<table border=\"1\" class=\"dataframe table table-stripe…" |
| 482 | + ] |
| 483 | + }, |
| 484 | + "metadata": {}, |
| 485 | + "output_type": "display_data" |
| 486 | + }, |
| 487 | + { |
| 488 | + "data": { |
| 489 | + "text/html": [], |
| 490 | + "text/plain": [ |
| 491 | + "Computation deferred. Computation will process 506.0 GB" |
| 492 | + ] |
| 493 | + }, |
| 494 | + "execution_count": 11, |
| 495 | + "metadata": {}, |
| 496 | + "output_type": "execute_result" |
| 497 | + } |
| 498 | + ], |
| 499 | + "source": [ |
| 500 | + "import datetime\n", |
| 501 | + "\n", |
| 502 | + " # Read the PyPI downloads dataset\n", |
| 503 | + "pypi_df = bpd.read_gbq(\"bigquery-public-data.pypi.file_downloads\")\n", |
| 504 | + "\n", |
| 505 | + "# Filter for the last 7 days to reduce the data size for this example\n", |
| 506 | + "seven_days_ago = datetime.datetime.now(datetime.timezone.utc) - datetime.timedelta(days=7)\n", |
| 507 | + "pypi_df_recent = pypi_df[pypi_df[\"timestamp\"] > seven_days_ago]\n", |
| 508 | + " \n", |
| 509 | + "# Create a multi-index by grouping by date and project\n", |
| 510 | + "pypi_df_recent['date'] = pypi_df_recent['timestamp'].dt.date\n", |
| 511 | + "multi_index_df = pypi_df_recent.groupby([\"date\", \"project\"]).size().to_frame(\"downloads\")\n", |
| 512 | + " \n", |
| 513 | + "# Display the DataFrame with the multi-index\n", |
| 514 | + "multi_index_df" |
| 515 | + ] |
446 | 516 | } |
447 | 517 | ], |
448 | 518 | "metadata": { |
|
0 commit comments