Skip to content

Commit 5e20bb4

Browse files
committed
fix: update snapshot
1 parent 143c9ed commit 5e20bb4

File tree

3 files changed

+113
-29
lines changed

3 files changed

+113
-29
lines changed

marimo/_convert/ipynb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,8 +719,8 @@ def _transform_sources(
719719

720720
# Define transforms that don't need comment preservation
721721
simple_transforms = [
722-
transform_magic_commands,
723722
transform_strip_whitespace,
723+
transform_magic_commands,
724724
transform_exclamation_mark,
725725
transform_remove_duplicate_imports,
726726
]

tests/_convert/ipynb_data/comments_preservation.ipynb

Lines changed: 104 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,17 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": null,
5+
"execution_count": 2,
66
"metadata": {},
7+
"outputs": [
8+
{
9+
"name": "stdout",
10+
"output_type": "stream",
11+
"text": [
12+
"1\n"
13+
]
14+
}
15+
],
716
"source": [
817
"# Cell 1: Basic inline and line comments\n",
918
"x = 1 # This is an inline comment\n",
@@ -12,8 +21,17 @@
1221
},
1322
{
1423
"cell_type": "code",
15-
"execution_count": null,
24+
"execution_count": 3,
1625
"metadata": {},
26+
"outputs": [
27+
{
28+
"name": "stdout",
29+
"output_type": "stream",
30+
"text": [
31+
"10\n"
32+
]
33+
}
34+
],
1735
"source": [
1836
"# Cell 2: Comments with duplicate definitions\n",
1937
"# This variable will be redefined later\n",
@@ -23,8 +41,17 @@
2341
},
2442
{
2543
"cell_type": "code",
26-
"execution_count": null,
44+
"execution_count": 4,
2745
"metadata": {},
46+
"outputs": [
47+
{
48+
"name": "stdout",
49+
"output_type": "stream",
50+
"text": [
51+
"40\n"
52+
]
53+
}
54+
],
2855
"source": [
2956
"# Cell 3: Redefinition with more comments\n",
3057
"# This is the second definition of y\n",
@@ -35,8 +62,27 @@
3562
},
3663
{
3764
"cell_type": "code",
38-
"execution_count": null,
65+
"execution_count": 5,
3966
"metadata": {},
67+
"outputs": [
68+
{
69+
"name": "stdout",
70+
"output_type": "stream",
71+
"text": [
72+
"CPU times: user 4 μs, sys: 1 μs, total: 5 μs\n",
73+
"Wall time: 8.11 μs\n",
74+
"cell_metadata.ipynb\n",
75+
"comments_preservation.ipynb\n",
76+
"duplicate_definitions_and_aug_assign.ipynb\n",
77+
"duplicate_definitions_read_before_write.ipynb\n",
78+
"duplicate_definitions_syntax_error.ipynb\n",
79+
"hides_markdown_cells.ipynb\n",
80+
"multiple_definitions_multiline.ipynb\n",
81+
"multiple_definitions.ipynb\n",
82+
"pip_commands.ipynb\n"
83+
]
84+
}
85+
],
4086
"source": [
4187
"# Cell 4: Magic commands with comments\n",
4288
"%time x = 5 # Time this operation\n",
@@ -46,11 +92,18 @@
4692
},
4793
{
4894
"cell_type": "code",
49-
"execution_count": null,
95+
"execution_count": 6,
5096
"metadata": {},
97+
"outputs": [
98+
{
99+
"name": "stderr",
100+
"output_type": "stream",
101+
"text": [
102+
"UsageError: Cell magic `%%sql` not found.\n"
103+
]
104+
}
105+
],
51106
"source": [
52-
"# Cell 5: Multi-line magic with comments\n",
53-
"# This is a SQL query\n",
54107
"%%sql\n",
55108
"-- SQL comment inside magic\n",
56109
"SELECT * FROM table -- Another SQL comment\n",
@@ -59,8 +112,21 @@
59112
},
60113
{
61114
"cell_type": "code",
62-
"execution_count": null,
115+
"execution_count": 7,
63116
"metadata": {},
117+
"outputs": [
118+
{
119+
"ename": "ModuleNotFoundError",
120+
"evalue": "No module named 'numpy'",
121+
"output_type": "error",
122+
"traceback": [
123+
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
124+
"\u001b[31mModuleNotFoundError\u001b[39m Traceback (most recent call last)",
125+
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[7]\u001b[39m\u001b[32m, line 2\u001b[39m\n\u001b[32m 1\u001b[39m \u001b[38;5;66;03m# Cell 6: Comments with import statements\u001b[39;00m\n\u001b[32m----> \u001b[39m\u001b[32m2\u001b[39m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mnumpy\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mas\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mnp\u001b[39;00m \u001b[38;5;66;03m# Import numpy\u001b[39;00m\n\u001b[32m 3\u001b[39m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mpandas\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mas\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mpd\u001b[39;00m \u001b[38;5;66;03m# Import pandas\u001b[39;00m\n\u001b[32m 4\u001b[39m \u001b[38;5;66;03m# These imports might be duplicated elsewhere\u001b[39;00m\n",
126+
"\u001b[31mModuleNotFoundError\u001b[39m: No module named 'numpy'"
127+
]
128+
}
129+
],
64130
"source": [
65131
"# Cell 6: Comments with import statements\n",
66132
"import numpy as np # Import numpy\n",
@@ -70,8 +136,21 @@
70136
},
71137
{
72138
"cell_type": "code",
73-
"execution_count": null,
139+
"execution_count": 8,
74140
"metadata": {},
141+
"outputs": [
142+
{
143+
"ename": "ModuleNotFoundError",
144+
"evalue": "No module named 'numpy'",
145+
"output_type": "error",
146+
"traceback": [
147+
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
148+
"\u001b[31mModuleNotFoundError\u001b[39m Traceback (most recent call last)",
149+
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[8]\u001b[39m\u001b[32m, line 2\u001b[39m\n\u001b[32m 1\u001b[39m \u001b[38;5;66;03m# Cell 7: Duplicate import with different comment\u001b[39;00m\n\u001b[32m----> \u001b[39m\u001b[32m2\u001b[39m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mnumpy\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mas\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mnp\u001b[39;00m \u001b[38;5;66;03m# Import numpy again with different comment\u001b[39;00m\n\u001b[32m 3\u001b[39m \u001b[38;5;66;03m# This should be deduplicated but preserve one of the comments\u001b[39;00m\n\u001b[32m 4\u001b[39m arr = np.array([\u001b[32m1\u001b[39m, \u001b[32m2\u001b[39m, \u001b[32m3\u001b[39m]) \u001b[38;5;66;03m# Create array\u001b[39;00m\n",
150+
"\u001b[31mModuleNotFoundError\u001b[39m: No module named 'numpy'"
151+
]
152+
}
153+
],
75154
"source": [
76155
"# Cell 7: Duplicate import with different comment\n",
77156
"import numpy as np # Import numpy again with different comment\n",
@@ -81,8 +160,9 @@
81160
},
82161
{
83162
"cell_type": "code",
84-
"execution_count": null,
163+
"execution_count": 9,
85164
"metadata": {},
165+
"outputs": [],
86166
"source": [
87167
"# Cell 8: Complex expressions with comments\n",
88168
"# Calculate something complex\n",
@@ -93,8 +173,9 @@
93173
},
94174
{
95175
"cell_type": "code",
96-
"execution_count": null,
176+
"execution_count": 10,
97177
"metadata": {},
178+
"outputs": [],
98179
"source": [
99180
"# Cell 9: Augmented assignment with comments\n",
100181
"counter = 0 # Initialize counter\n",
@@ -104,8 +185,9 @@
104185
},
105186
{
106187
"cell_type": "code",
107-
"execution_count": null,
188+
"execution_count": 11,
108189
"metadata": {},
190+
"outputs": [],
109191
"source": [
110192
"# Cell 10: Function definitions with comments\n",
111193
"def my_function(): # Define a function\n",
@@ -114,11 +196,18 @@
114196
" return 42 # Return a value\n",
115197
"# Comment after function"
116198
]
199+
},
200+
{
201+
"cell_type": "code",
202+
"execution_count": null,
203+
"metadata": {},
204+
"outputs": [],
205+
"source": []
117206
}
118207
],
119208
"metadata": {
120209
"kernelspec": {
121-
"display_name": "Python 3",
210+
"display_name": "Python 3 (ipykernel)",
122211
"language": "python",
123212
"name": "python3"
124213
},
@@ -132,9 +221,9 @@
132221
"name": "python",
133222
"nbconvert_exporter": "python",
134223
"pygments_lexer": "ipython3",
135-
"version": "3.8.0"
224+
"version": "3.12.11"
136225
}
137226
},
138227
"nbformat": 4,
139228
"nbformat_minor": 4
140-
}
229+
}

tests/_convert/snapshots/convert_comments_preservation.py.txt

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,14 @@ def _():
4141
return
4242

4343

44-
app._unparsable_cell(
45-
r"""
46-
# Cell 5: Multi-line magic with comments
47-
# This is a SQL query
48-
_df = mo.sql(\"\"\"
49-
50-
\"\"\")
44+
@app.cell
45+
def _(mo):
46+
_df = mo.sql("""
5147
-- SQL comment inside magic
5248
SELECT * FROM table -- Another SQL comment
5349
WHERE id > 0 # Python-style comment in SQL
54-
""",
55-
name="_"
56-
)
50+
""")
51+
return
5752

5853

5954
@app.cell
@@ -66,11 +61,11 @@ def _():
6661

6762

6863
@app.cell
69-
def _(np_1):
64+
def _():
7065
# Cell 7: Duplicate import with different comment
7166
import numpy as np # Import numpy again with different comment
7267
# This should be deduplicated but preserve one of the comments
73-
arr = np_1.array([1, 2, 3]) # Create array
68+
arr = _np.array([1, 2, 3]) # Create array
7469
return
7570

7671

@@ -106,7 +101,7 @@ def _():
106101
@app.cell
107102
def _():
108103
import marimo as mo
109-
return
104+
return (mo,)
110105

111106

112107
if __name__ == "__main__":

0 commit comments

Comments
 (0)