Skip to content

Commit 3e80dc9

Browse files
authored
update system prompt & claude.md (#6437)
## 📝 Summary <!-- Provide a concise summary of what this pull request is addressing. If this PR fixes any issues, list them here by number (e.g., Fixes #123). --> - Use polars instead of pandas - Altair instead of pyplot - Add a short sql cell guide (don't return df, pass in engine name) ## 🔍 Description of Changes <!-- Detail the specific changes made in this pull request. Explain the problem addressed and how it was resolved. If applicable, provide before and after comparisons, screenshots, or any relevant details to help reviewers understand the changes easily. --> ## 📋 Checklist - [x] I have read the [contributor guidelines](https://github.com/marimo-team/marimo/blob/main/CONTRIBUTING.md). - [ ] For large changes, or changes that affect the public API: this change was discussed or approved through an issue, on [Discord](https://marimo.io/discord?ref=pr), or the community [discussions](https://github.com/marimo-team/marimo/discussions) (Please provide a link if applicable). - [x] I have added tests for the changes made. - [x] I have run the code and verified that it works as expected.
1 parent e985313 commit 3e80dc9

File tree

6 files changed

+402
-203
lines changed

6 files changed

+402
-203
lines changed

docs/_static/CLAUDE.md

Lines changed: 65 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Marimo's reactivity means:
4646

4747
<data_handling>
4848

49-
- Use pandas for data manipulation
49+
- Use polars for data manipulation
5050
- Implement proper data validation
5151
- Handle missing values appropriately
5252
- Use efficient data structures
@@ -56,7 +56,7 @@ Marimo's reactivity means:
5656
<visualization>
5757
- For matplotlib: use plt.gca() as the last expression instead of plt.show()
5858
- For plotly: return the figure object directly
59-
- For altair: return the chart object directly
59+
- For altair: return the chart object directly. Add tooltips where appropriate. You can pass polars dataframes directly to altair.
6060
- Include proper labels, titles, and color schemes
6161
- Make visualizations interactive where appropriate
6262
</visualization>
@@ -79,7 +79,7 @@ Marimo's reactivity means:
7979
</data_sources>
8080

8181
<sql>
82-
- When writing duckdb, prefer using marimo's SQL cells, which start with _df = mo.sql(query)
82+
- When writing duckdb, prefer using marimo's SQL cells, which start with df = mo.sql(f"""<your query>""") for DuckDB, or df = mo.sql(f"""<your query>""", engine=engine) for other SQL engines.
8383
- See the SQL with duckdb example for an example on how to do this
8484
- Don't add comments in cells that use mo.sql()
8585
- Consider using \`vega_datasets\` for common example datasets
@@ -132,7 +132,8 @@ Common issues and solutions:
132132
<example title="Basic UI with reactivity">
133133
# Cell 1
134134
import marimo as mo
135-
import matplotlib.pyplot as plt
135+
import altair as alt
136+
import polars as pl
136137
import numpy as np
137138

138139
# Cell 2
@@ -151,59 +152,64 @@ n_points # Display the slider
151152
x = np.random.rand(n_points.value)
152153
y = np.random.rand(n_points.value)
153154

154-
plt.figure(figsize=(8, 6))
155-
plt.scatter(x, y, alpha=0.7)
156-
plt.title(f"Scatter plot with {n_points.value} points")
157-
plt.xlabel("X axis")
158-
plt.ylabel("Y axis")
159-
plt.gca() # Return the current axes to display the plot
155+
df = pl.DataFrame({"x": x, "y": y})
156+
157+
chart = alt.Chart(df).mark_circle(opacity=0.7).encode(
158+
x=alt.X('x', title='X axis'),
159+
y=alt.Y('y', title='Y axis')
160+
).properties(
161+
title=f"Scatter plot with {n_points.value} points",
162+
width=400,
163+
height=300
164+
)
165+
166+
chart
160167
</example>
161168

162169
<example title="Data explorer">
163170
# Cell 1
164171
import marimo as mo
165-
import pandas as pd
172+
import polars as pl
166173
from vega_datasets import data
167174

168175
# Cell 2
169176

170177
# Load and display dataset with interactive explorer
171178

172-
cars_df = data.cars()
179+
cars_df = pl.DataFrame(data.cars())
173180
mo.ui.data_explorer(cars_df)
174181
</example>
175182

176183
<example title="Multiple UI elements">
177184
# Cell 1
178185
import marimo as mo
179-
import pandas as pd
180-
import matplotlib.pyplot as plt
181-
import seaborn as sns
186+
import polars as pl
187+
import altair as alt
182188

183189
# Cell 2
184190

185191
# Load dataset
186192

187-
iris = sns.load_dataset('iris')
193+
iris = pl.read_csv("hf://datasets/scikit-learn/iris/Iris.csv")
188194

189195
# Cell 3
190196

191197
# Create UI elements
192198

193199
species_selector = mo.ui.dropdown(
194-
options=["All"] + iris["species"].unique().tolist(),
200+
options=["All"] + iris["Species"].unique().to_list(),
195201
value="All",
196-
label="Species"
202+
label="Species",
197203
)
198204
x_feature = mo.ui.dropdown(
199-
options=iris.select_dtypes('number').columns.tolist(),
200-
value="sepal_length",
201-
label="X Feature"
205+
options=iris.select(pl.col(pl.Float64, pl.Int64)).columns,
206+
value="SepalLengthCm",
207+
label="X Feature",
202208
)
203209
y_feature = mo.ui.dropdown(
204-
options=iris.select_dtypes('number').columns.tolist(),
205-
value="sepal_width",
206-
label="Y Feature"
210+
options=iris.select(pl.col(pl.Float64, pl.Int64)).columns,
211+
value="SepalWidthCm",
212+
label="Y Feature",
207213
)
208214

209215
# Display UI elements in a horizontal stack
@@ -214,36 +220,45 @@ mo.hstack([species_selector, x_feature, y_feature])
214220

215221
# Filter data based on selection
216222

217-
filtered_data = iris if species_selector.value == "All" else iris[iris["species"] == species_selector.value]
223+
filtered_data = iris if species_selector.value == "All" else iris.filter(pl.col("Species") == species_selector.value)
218224

219225
# Create visualization based on UI selections
220226

221-
plt.figure(figsize=(10, 6))
222-
sns.scatterplot(
223-
data=filtered_data,
224-
x=x_feature.value,
225-
y=y_feature.value,
226-
hue="species"
227+
chart = alt.Chart(filtered_data).mark_circle().encode(
228+
x=alt.X(x_feature.value, title=x_feature.value),
229+
y=alt.Y(y_feature.value, title=y_feature.value),
230+
color='Species'
231+
).properties(
232+
title=f"{y_feature.value} vs {x_feature.value}",
233+
width=500,
234+
height=400
227235
)
228-
plt.title(f"{y_feature.value} vs {x_feature.value}")
229-
plt.gca()
236+
237+
chart
230238
</example>
231239

232240
<example title="Interactive chart with Altair">
233241
# Cell 1
234242
import marimo as mo
235243
import altair as alt
236-
import pandas as pd
244+
import polars as pl
237245

238246
# Cell 2
239247

240248
# Load dataset
241249

242-
cars_df = pd.read_csv('<https://raw.githubusercontent.com/vega/vega-datasets/master/data/cars.json>')
243-
_chart = alt.Chart(cars_df).mark_point().encode(
244-
x='Horsepower',
245-
y='Miles_per_Gallon',
246-
color='Origin',
250+
weather = pl.read_csv("https://raw.githubusercontent.com/vega/vega-datasets/refs/heads/main/data/weather.csv")
251+
weather_dates = weather.with_columns(
252+
pl.col("date").str.strptime(pl.Date, format="%Y-%m-%d")
253+
)
254+
_chart = (
255+
alt.Chart(weather_dates)
256+
.mark_point()
257+
.encode(
258+
x="date:T",
259+
y="temp_max",
260+
color="location",
261+
)
247262
)
248263

249264
chart = mo.ui.altair_chart(_chart)
@@ -279,16 +294,21 @@ else:
279294
<example title="SQL with duckdb">
280295
# Cell 1
281296
import marimo as mo
297+
import polars as pl
282298

283299
# Cell 2
284300

285301
# Load dataset
286302

287-
cars_df = pd.read_csv('<https://raw.githubusercontent.com/vega/vega-datasets/master/data/cars.json>')
303+
weather = pl.read_csv("https://raw.githubusercontent.com/vega/vega-datasets/refs/heads/main/data/weather.csv")
288304

289305
# Cell 3
290306

291-
_df = mo.sql("SELECT * from cars_df WHERE Miles_per_Gallon > 20")
307+
seattle_weather_df = mo.sql(
308+
f"""
309+
SELECT * FROM weather WHERE location = 'Seattle';
310+
"""
311+
)
292312
</example>
293313

294314
<example title="Writing LaTeX in markdown">
@@ -297,10 +317,11 @@ import marimo as mo
297317

298318
# Cell 2
299319

300-
mo.md(r"""
301-
320+
mo.md(
321+
r"""
302322
The quadratic function $f$ is defined as
303323

304324
$$f(x) = x^2.$$
305-
""")
325+
"""
326+
)
306327
</example>

0 commit comments

Comments
 (0)