Skip to content

Commit ec7a56a

Browse files
committed
test: add test_cell_execution_widgets notebook
1 parent 5f9d824 commit ec7a56a

1 file changed

Lines changed: 106 additions & 0 deletions

File tree

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
{
2+
"cells": [
3+
{
4+
"id": "300728e0",
5+
"cell_type": "markdown",
6+
"source": [
7+
"# Testing TableWidget Cell Execution Count Propagation on Sorting\n",
8+
"\n",
9+
"This notebook verifies that if multiple `TableWidget`s are rendered across different notebook cells, triggering sorting in a widget preserves and uses the original cell's execution count for the new query, rather than the active cell's execution count."
10+
],
11+
"metadata": {}
12+
},
13+
{
14+
"id": "52dfd39a",
15+
"cell_type": "code",
16+
"source": [
17+
"import bigframes\n",
18+
"import bigframes.pandas as bpd\n",
19+
"\n",
20+
"bpd.options.bigquery.location = \"US\"\n",
21+
"bpd.options.display.render_mode = \"anywidget\""
22+
],
23+
"metadata": {},
24+
"execution_count": null,
25+
"outputs": []
26+
},
27+
{
28+
"id": "d14207ff",
29+
"cell_type": "markdown",
30+
"source": [
31+
"## Cell 1: Create and render the first DataFrame widget\n",
32+
"\n",
33+
"We will render a TableWidget in this cell. The captured cell execution count of this widget will be associated with this cell."
34+
],
35+
"metadata": {}
36+
},
37+
{
38+
"id": "2e74b4f4",
39+
"cell_type": "code",
40+
"source": [
41+
"df1 = bpd.read_gbq(\"SELECT 10 AS id, 'alice' AS name UNION ALL SELECT 20 AS id, 'bob' AS name\")\n",
42+
"df1"
43+
],
44+
"metadata": {},
45+
"execution_count": null,
46+
"outputs": []
47+
},
48+
{
49+
"id": "7228323e",
50+
"cell_type": "markdown",
51+
"source": [
52+
"## Cell 2: Create and render the second DataFrame widget\n",
53+
"\n",
54+
"Now we render a second TableWidget. It should capture its own cell execution count."
55+
],
56+
"metadata": {}
57+
},
58+
{
59+
"id": "4fc5012f",
60+
"cell_type": "code",
61+
"source": [
62+
"df2 = bpd.read_gbq(\"SELECT 100 AS val, 'x' AS label UNION ALL SELECT 200 AS val, 'y' AS label\")\n",
63+
"df2"
64+
],
65+
"metadata": {},
66+
"execution_count": null,
67+
"outputs": []
68+
},
69+
{
70+
"id": "00f54ffe",
71+
"cell_type": "markdown",
72+
"source": [
73+
"## Testing Instructions\n",
74+
"\n",
75+
"1. Sort the **first** widget (`df1`) by clicking on the `name` or `id` column header in the rendered table in Cell 1.\n",
76+
"2. Run the code cell below to view the session's execution history.\n",
77+
"3. Verify that the new query job triggered by sorting is associated with the cell execution count of Cell 1, rather than subsequent cells."
78+
],
79+
"metadata": {}
80+
},
81+
{
82+
"id": "7b313176",
83+
"cell_type": "code",
84+
"source": [
85+
"# Show all execution history with their associated cell execution count\n",
86+
"history = bigframes.execution_history(current_cell_only=False)\n",
87+
"history.to_dataframe()[[\"job_id\", \"query\", \"cell_execution_count\"]]"
88+
],
89+
"metadata": {},
90+
"execution_count": null,
91+
"outputs": []
92+
}
93+
],
94+
"metadata": {
95+
"kernelspec": {
96+
"display_name": "Python 3",
97+
"language": "python",
98+
"name": "python3"
99+
},
100+
"language_info": {
101+
"name": "python"
102+
}
103+
},
104+
"nbformat_minor": 5,
105+
"nbformat": 4
106+
}

0 commit comments

Comments
 (0)