A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
fix: latex mime, exlclude text/plain, depcheck perf (#2295)
Myles Scolnicka98fd14672a7
diff --git a/marimo/_data/series.py b/marimo/_data/series.pyindex 5358f804fd..f54b123e3e 100644--- a/marimo/_data/series.py+++ b/marimo/_data/series.py@@ -61,7 +61,7 @@ def get_number_series_info(series: Any) -> NumberSeriesInfo:raise ValueError("Expected a number. Got: " + str(type(value)))return value- if DependencyManager.pandas.has():+ if DependencyManager.pandas.imported():import pandas as pdif isinstance(series, pd.Series):@@ -71,7 +71,7 @@ def get_number_series_info(series: Any) -> NumberSeriesInfo:label=_get_name(series),)- if DependencyManager.polars.has():+ if DependencyManager.polars.imported():import polars as plif isinstance(series, pl.Series):@@ -88,7 +88,7 @@ def get_category_series_info(series: Any) -> CategorySeriesInfo:"""Get the summary of a categorical series."""- if DependencyManager.pandas.has():+ if DependencyManager.pandas.imported():import pandas as pdif isinstance(series, pd.Series):@@ -97,7 +97,7 @@ def get_category_series_info(series: Any) -> CategorySeriesInfo:label=_get_name(series),)- if DependencyManager.polars.has():+ if DependencyManager.polars.imported():import polars as plif isinstance(series, pl.Series):@@ -119,7 +119,7 @@ def get_date_series_info(series: Any) -> DateSeriesInfo:raise ValueError("Expected a date. Got: " + str(type(value)))return value.strftime("%Y-%m-%d")- if DependencyManager.pandas.has():+ if DependencyManager.pandas.imported():import pandas as pdif isinstance(series, pd.Series):@@ -129,7 +129,7 @@ def get_date_series_info(series: Any) -> DateSeriesInfo:label=_get_name(series),)- if DependencyManager.polars.has():+ if DependencyManager.polars.imported():import polars as plif isinstance(series, pl.Series):@@ -156,7 +156,7 @@ def get_datetime_series_info(series: Any) -> DateSeriesInfo:return value.strftime("%Y-%m-%d")raise ValueError("Expected a datetime. Got: " + str(type(value)))- if DependencyManager.pandas.has():+ if DependencyManager.pandas.imported():import pandas as pdif isinstance(series, pd.Series):@@ -166,7 +166,7 @@ def get_datetime_series_info(series: Any) -> DateSeriesInfo:label=_get_name(series),)- if DependencyManager.polars.has():+ if DependencyManager.polars.imported():import polars as plif isinstance(series, pl.Series):diff --git a/marimo/_output/formatting.py b/marimo/_output/formatting.pyindex ae85b9209b..07877d3601 100644--- a/marimo/_output/formatting.py+++ b/marimo/_output/formatting.py@@ -161,7 +161,9 @@ def get_formatter(("_repr_png_", "image/png"),("_repr_jpeg_", "image/jpeg"),("_repr_markdown_", "text/markdown"),- ("_repr_latex_", "text/latex"),+ # Commenting out _repr_latex_ for now, since pandas pd.Series+ # uses it for some reason, but returns empty+ # ("_repr_latex_", "text/latex"),("_repr_text_", "text/plain"), # last]@@ -173,7 +175,23 @@ def get_formatter(mime_type: KnownMimeType = mime_type,attr: str = attr,) -> tuple[KnownMimeType, str]:- contents = getattr(obj, attr)()+ method = getattr(obj, attr)+ # Try to call _repr_mimebundle_ with include/exclude parameters+ if attr == "_repr_mimebundle_":+ try:+ contents = method(include=[], exclude=[])+ except TypeError:+ # If that fails, call the method without parameters+ contents = method()+ # Remove text/plain from the mimebundle if it's present+ # since there are other representations available+ # N.B. We cannot pass this as an argument to the method+ # because this unfortunately could break some libraries+ # (e.g. ibis)+ if "text/plain" in contents and len(contents) > 1:+ contents.pop("text/plain")+ else:+ contents = method()# Handle the case where the contents are bytesif isinstance(contents, bytes):@@ -188,7 +206,7 @@ def get_formatter(if mime_type in md_mime_types:from marimo._output.md import md- return ("text/html", md(contents).text)+ return ("text/html", md(contents or "_empty_").text)return (mime_type, contents)diff --git a/marimo/_plugins/core/json_encoder.py b/marimo/_plugins/core/json_encoder.pyindex ac7910a4a7..0049af8aea 100644--- a/marimo/_plugins/core/json_encoder.py+++ b/marimo/_plugins/core/json_encoder.py@@ -16,7 +16,7 @@ class WebComponentEncoder(JSONEncoder):def default(self, o: Any) -> Any:obj = o# Handle numpy objects- if DependencyManager.numpy.has():+ if DependencyManager.numpy.imported():import numpy as npdtypes = (np.datetime64, np.complexfloating)@@ -34,7 +34,7 @@ class WebComponentEncoder(JSONEncoder):return str(obj)# Handle pandas objects- if DependencyManager.pandas.has():+ if DependencyManager.pandas.imported():import pandas as pd# Opinionated or known typesdiff --git a/marimo/_plugins/ui/_impl/altair_chart.py b/marimo/_plugins/ui/_impl/altair_chart.pyindex 3c989295b0..2df6c24aff 100644--- a/marimo/_plugins/ui/_impl/altair_chart.py+++ b/marimo/_plugins/ui/_impl/altair_chart.py@@ -54,7 +54,13 @@ def _has_binning(spec: VegaSpec) -> bool:def _has_geoshape(spec: altair.TopLevelMixin) -> bool:"""Return True if the spec has geoshape."""- return hasattr(spec, "mark") and spec.mark == "geoshape"+ try:+ if not hasattr(spec, "mark"):+ return False+ mark = spec.mark # type: ignore+ return mark == "geoshape" or mark.type == "geoshape" # type: ignore+ except Exception:+ return Falsedef _filter_dataframe(@@ -63,13 +69,13 @@ def _filter_dataframe(if not isinstance(selection, dict):raise TypeError("Input 'selection' must be a dictionary")- if DependencyManager.pandas.has():+ if DependencyManager.pandas.imported():import pandas as pdif isinstance(df, pd.DataFrame):return _filter_pandas_dataframe(df, selection)- if DependencyManager.polars.has():+ if DependencyManager.polars.imported():import polars as plif isinstance(df, pl.DataFrame):@@ -435,7 +441,7 @@ class altair_chart(UIElement[ChartSelection, ChartDataType]):if not isinstance(chart.data, str):return chart.data- if DependencyManager.pandas.has():+ if DependencyManager.pandas.imported():import pandas as pdif chart.data.endswith(".csv"):@@ -443,7 +449,7 @@ class altair_chart(UIElement[ChartSelection, ChartDataType]):if chart.data.endswith(".json"):return pd.read_json(chart.data)- if DependencyManager.polars.has():+ if DependencyManager.polars.imported():import polars as plif chart.data.startswith("http"):@@ -468,6 +474,18 @@ class altair_chart(UIElement[ChartSelection, ChartDataType]):self._chart_selection = valueflat, _ = flatten.flatten(value)if not value or not flat:+ if DependencyManager.pandas.imported():+ import pandas as pd++ if isinstance(self.dataframe, pd.DataFrame):+ return pd.DataFrame()++ if DependencyManager.polars.imported():+ import polars as pl++ if isinstance(self.dataframe, pl.DataFrame):+ return pl.DataFrame()+return []# When using layered charts, you can no longer access thediff --git a/marimo/_plugins/ui/_impl/dataframes/transforms/apply.py b/marimo/_plugins/ui/_impl/dataframes/transforms/apply.pyindex c6d4b0f96c..cc48953c07 100644--- a/marimo/_plugins/ui/_impl/dataframes/transforms/apply.py+++ b/marimo/_plugins/ui/_impl/dataframes/transforms/apply.py@@ -65,18 +65,18 @@ def get_handler_for_dataframe(raises ValueError if the dataframe type is not supported."""- if DependencyManager.pandas.has():+ if DependencyManager.pandas.imported():import pandas as pdif isinstance(df, pd.DataFrame):return PandasTransformHandler()- if DependencyManager.polars.has():+ if DependencyManager.polars.imported():import polars as plif isinstance(df, pl.DataFrame):return PolarsTransformHandler()- if DependencyManager.ibis.has():+ if DependencyManager.ibis.imported():import ibis # type: ignoreif isinstance(df, ibis.Table):diff --git a/marimo/_smoke_tests/admonitions.py b/marimo/_smoke_tests/admonitions.pyindex 917ed10a8a..401a38d0bb 100644--- a/marimo/_smoke_tests/admonitions.py+++ b/marimo/_smoke_tests/admonitions.py@@ -1,3 +1,9 @@+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "marimo",+# ]+# ///# Copyright 2024 Marimo. All rights reserved.import marimodiff --git a/marimo/_smoke_tests/altair/altair_brush.py b/marimo/_smoke_tests/altair/altair_brush.pyindex 351849c836..33873c89ec 100644--- a/marimo/_smoke_tests/altair/altair_brush.py+++ b/marimo/_smoke_tests/altair/altair_brush.py@@ -1,3 +1,12 @@+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "pandas",+# "altair",+# "marimo",+# "numpy",+# ]+# ///# Copyright 2024 Marimo. All rights reserved.import marimodiff --git a/marimo/_smoke_tests/altair/altair_charts.py b/marimo/_smoke_tests/altair/altair_charts.pyindex 26caf3b74a..2edb5306c8 100644--- a/marimo/_smoke_tests/altair/altair_charts.py+++ b/marimo/_smoke_tests/altair/altair_charts.py@@ -1,8 +1,17 @@-# Copyright 2024 Marimo. All rights reserved.+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "marimo",+# "pandas",+# "numpy",+# "vega-datasets",+# "altair",+# ]+# ///import marimo-__generated_with = "0.8.2"+__generated_with = "0.8.14"app = marimo.App(width="full")@@ -221,7 +230,7 @@ def __(mo):@app.celldef __(chart3, mo):- mo.hstack([chart3, chart3.value.head(10)])+ mo.hstack([chart3, chart3.value.head(10)], widths="equal")returndiff --git a/marimo/_smoke_tests/altair/altair_geoshape.py b/marimo/_smoke_tests/altair/altair_geoshape.pyindex 3e9407513e..c2df0467d8 100644--- a/marimo/_smoke_tests/altair/altair_geoshape.py+++ b/marimo/_smoke_tests/altair/altair_geoshape.py@@ -1,7 +1,16 @@-# Copyright 2024 Marimo. All rights reserved.+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "marimo",+# "altair",+# "vega-datasets",+# "geopandas",+# ]+# ///+import marimo-__generated_with = "0.7.20"+__generated_with = "0.8.14"app = marimo.App(width="medium")@@ -45,6 +54,12 @@ def __(chart):return+def __(chart):+ chart.mark.type+ return++@app.celldef __(chart, mo):mo_chart = mo.ui.altair_chart(chart)diff --git a/marimo/_smoke_tests/altair/altair_polars.py b/marimo/_smoke_tests/altair/altair_polars.pyindex b74a18c01d..8009a6bd91 100644--- a/marimo/_smoke_tests/altair/altair_polars.py+++ b/marimo/_smoke_tests/altair/altair_polars.py@@ -1,4 +1,11 @@-# Copyright 2024 Marimo. All rights reserved.+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "marimo",+# "altair",+# "polars",+# ]+# ///import marimo__generated_with = "0.8.2"diff --git a/marimo/_smoke_tests/ansi.py b/marimo/_smoke_tests/ansi.pyindex 0a64b9a937..a2cee0233c 100644--- a/marimo/_smoke_tests/ansi.py+++ b/marimo/_smoke_tests/ansi.py@@ -1,3 +1,9 @@+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "marimo",+# ]+# ///# Copyright 2024 Marimo. All rights reserved.import marimodiff --git a/marimo/_smoke_tests/anywidget/maplibre_example.py b/marimo/_smoke_tests/anywidget/maplibre_example.pyindex c1bb5b7a06..02868967f6 100644--- a/marimo/_smoke_tests/anywidget/maplibre_example.py+++ b/marimo/_smoke_tests/anywidget/maplibre_example.py@@ -1,4 +1,10 @@-# Copyright 2024 Marimo. All rights reserved.+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "marimo",+# "maplibre",+# ]+# ///import marimodiff --git a/marimo/_smoke_tests/anywidget/mosaic_example.py b/marimo/_smoke_tests/anywidget/mosaic_example.pyindex a98284acf8..9841d9a23f 100644--- a/marimo/_smoke_tests/anywidget/mosaic_example.py+++ b/marimo/_smoke_tests/anywidget/mosaic_example.py@@ -1,3 +1,12 @@+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "pandas",+# "mosaic-widget",+# "marimo",+# "pyyaml",+# ]+# ///# Copyright 2024 Marimo. All rights reserved.import marimodiff --git a/marimo/_smoke_tests/anywidget_compat.py b/marimo/_smoke_tests/anywidget_compat.pyindex 354a021cff..6056ef3a37 100644--- a/marimo/_smoke_tests/anywidget_compat.py+++ b/marimo/_smoke_tests/anywidget_compat.py@@ -1,4 +1,14 @@-# Copyright 2024 Marimo. All rights reserved.+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "marimo",+# "traitlets",+# "anywidget",+# "pandas",+# "altair",+# "drawdata",+# ]+# ///import marimo__generated_with = "0.2.13"diff --git a/marimo/_smoke_tests/arrays_and_dicts.py b/marimo/_smoke_tests/arrays_and_dicts.pyindex 81e984f126..7e4019c6f6 100644--- a/marimo/_smoke_tests/arrays_and_dicts.py+++ b/marimo/_smoke_tests/arrays_and_dicts.py@@ -1,3 +1,9 @@+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "marimo",+# ]+# ///# Copyright 2024 Marimo. All rights reserved.import marimodiff --git a/marimo/_smoke_tests/buttons.py b/marimo/_smoke_tests/buttons.pyindex 327af4334b..df5babb6bd 100644--- a/marimo/_smoke_tests/buttons.py+++ b/marimo/_smoke_tests/buttons.py@@ -1,3 +1,9 @@+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "marimo",+# ]+# ///# Copyright 2024 Marimo. All rights reserved.import marimodiff --git a/marimo/_smoke_tests/carousel.py b/marimo/_smoke_tests/carousel.pyindex 248156bade..8d9d4d3bf3 100644--- a/marimo/_smoke_tests/carousel.py+++ b/marimo/_smoke_tests/carousel.py@@ -1,3 +1,11 @@+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "marimo",+# "altair",+# "pandas",+# ]+# ///# Copyright 2024 Marimo. All rights reserved.import marimodiff --git a/marimo/_smoke_tests/charts/1mil_flights.py b/marimo/_smoke_tests/charts/1mil_flights.pyindex 9429ac4bc9..52ff8436f8 100644--- a/marimo/_smoke_tests/charts/1mil_flights.py+++ b/marimo/_smoke_tests/charts/1mil_flights.py@@ -1,3 +1,12 @@+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "vega-datasets",+# "altair",+# "pandas",+# "marimo",+# ]+# ///# Copyright 2024 Marimo. All rights reserved.import marimodiff --git a/marimo/_smoke_tests/cli_args.py b/marimo/_smoke_tests/cli_args.pyindex a986f54352..d3790cd620 100644--- a/marimo/_smoke_tests/cli_args.py+++ b/marimo/_smoke_tests/cli_args.py@@ -1,7 +1,14 @@+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "marimo",+# ]+# ///# Copyright 2024 Marimo. All rights reserved.+import marimo-__generated_with = "0.4.0"+__generated_with = "0.8.14"app = marimo.App()@@ -13,13 +20,15 @@ def __():@app.celldef __(mo):- mo.md("""- Re-run this with notebook with the following command line:-- ```bash- marimo edit marimo/_smoke_tests/cli_args.py -- -a foo --b=bar -d 10 -d 20 -d false- ```- """)+ mo.md(+ """+ Re-run this with notebook with the following command line:++ ```bash+ marimo edit marimo/_smoke_tests/cli_args.py -- -a foo --b=bar -d 10 -d 20 -d false+ ```+ """+ )returndiff --git a/marimo/_smoke_tests/code_editor.py b/marimo/_smoke_tests/code_editor.pyindex acb5185d1a..392142e275 100644--- a/marimo/_smoke_tests/code_editor.py+++ b/marimo/_smoke_tests/code_editor.py@@ -1,3 +1,9 @@+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "marimo",+# ]+# ///# Copyright 2024 Marimo. All rights reserved.import marimodiff --git a/marimo/_smoke_tests/data_explorer.py b/marimo/_smoke_tests/data_explorer.pyindex 8ba6d4b57e..4008592580 100644--- a/marimo/_smoke_tests/data_explorer.py+++ b/marimo/_smoke_tests/data_explorer.py@@ -1,3 +1,10 @@+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "vega-datasets",+# "marimo",+# ]+# ///# Copyright 2024 Marimo. All rights reserved.import marimodiff --git a/marimo/_smoke_tests/dataframe.py b/marimo/_smoke_tests/dataframe.pyindex 927cb3e02c..c346b0c189 100644--- a/marimo/_smoke_tests/dataframe.py+++ b/marimo/_smoke_tests/dataframe.py@@ -8,12 +8,13 @@# "pyarrow",# "marimo",# "pandas",+# "ibis",# ]# ///import marimo-__generated_with = "0.8.7"+__generated_with = "0.8.14"app = marimo.App(width="full")@@ -307,24 +308,6 @@ def __():return alt, cars, mo, pa, pd, pl, vega_datasets-app._unparsable_cell(- r"""- SELECT * FROM cars WHERE Cylinders > 6;- """,- name="__"-)---def __(mo):- _df = mo.sql(- f"""- SELECT * FROM- """- )- return--@app.celldef __(cars, mo):_df = mo.sql(diff --git a/marimo/_smoke_tests/from_series.py b/marimo/_smoke_tests/from_series.pyindex 2842ff892b..ee601f84d7 100644--- a/marimo/_smoke_tests/from_series.py+++ b/marimo/_smoke_tests/from_series.py@@ -1,4 +1,11 @@-# Copyright 2024 Marimo. All rights reserved.+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "vega-datasets",+# "marimo",+# "polars",+# ]+# ///import marimo__generated_with = "0.6.23"diff --git a/marimo/_smoke_tests/full_width.py b/marimo/_smoke_tests/full_width.pyindex ac1994fd18..4c891be1a4 100644--- a/marimo/_smoke_tests/full_width.py+++ b/marimo/_smoke_tests/full_width.py@@ -1,3 +1,9 @@+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "marimo",+# ]+# ///# Copyright 2024 Marimo. All rights reserved.import marimodiff --git a/marimo/_smoke_tests/grid.py b/marimo/_smoke_tests/grid.pyindex 67ba936b4e..cefbefd712 100644--- a/marimo/_smoke_tests/grid.py+++ b/marimo/_smoke_tests/grid.py@@ -1,7 +1,8 @@# Copyright 2024 Marimo. All rights reserved.+import marimo-__generated_with = "0.1.8"+__generated_with = "0.8.14"app = marimo.App(layout_file="layouts/grid.grid.json")@@ -24,7 +25,7 @@ def __(mo):@app.celldef __(mo):- mo.md("# Horizontal Stack: `hstack`")+ mo.md("""# Horizontal Stack: `hstack`""")return@@ -42,7 +43,7 @@ def __(align, boxes, gap, justify, mo, wrap):@app.celldef __(mo):- mo.md("# Vertical Stack: `vstack`")+ mo.md("""# Vertical Stack: `vstack`""")returndiff --git a/marimo/_smoke_tests/icons.py b/marimo/_smoke_tests/icons.pyindex ec543cf455..7bb1a6737b 100644--- a/marimo/_smoke_tests/icons.py+++ b/marimo/_smoke_tests/icons.py@@ -1,3 +1,9 @@+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "marimo",+# ]+# ///# Copyright 2024 Marimo. All rights reserved.import marimodiff --git a/marimo/_smoke_tests/layout.py b/marimo/_smoke_tests/layout.pyindex f426d4eccb..bb6dfba6c3 100644--- a/marimo/_smoke_tests/layout.py+++ b/marimo/_smoke_tests/layout.py@@ -1,7 +1,8 @@# Copyright 2024 Marimo. All rights reserved.+import marimo-__generated_with = "0.1.3"+__generated_with = "0.8.14"app = marimo.App()@@ -24,7 +25,7 @@ def __(mo):@app.celldef __(mo):- mo.md("# Horizontal Stack: `hstack`")+ mo.md("""# Horizontal Stack: `hstack`""")return@@ -42,7 +43,7 @@ def __(align, boxes, gap, justify, mo, wrap):@app.celldef __(mo):- mo.md("# Vertical Stack: `vstack`")+ mo.md("""# Vertical Stack: `vstack`""")returndiff --git a/marimo/_smoke_tests/md.py b/marimo/_smoke_tests/md.pyindex 251bd578a2..318953cca7 100644--- a/marimo/_smoke_tests/md.py+++ b/marimo/_smoke_tests/md.py@@ -1,7 +1,14 @@+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "marimo",+# ]+# ///# Copyright 2024 Marimo. All rights reserved.+import marimo-__generated_with = "0.2.1"+__generated_with = "0.8.14"app = marimo.App()@@ -13,7 +20,7 @@ def __():@app.celldef __(mo):- mo.md("# Tables")+ mo.md("""# Tables""")return@@ -46,7 +53,7 @@ def __(mo):@app.celldef __(mo):- mo.md("# Footnotes")+ mo.md("""# Footnotes""")return@@ -72,7 +79,7 @@ def __(mo):@app.celldef __(mo):- mo.md("# External links")+ mo.md("""# External links""")returndiff --git a/marimo/_smoke_tests/nav_menus.py b/marimo/_smoke_tests/nav_menus.pyindex ef974bb8af..d3053ef16f 100644--- a/marimo/_smoke_tests/nav_menus.py+++ b/marimo/_smoke_tests/nav_menus.py@@ -2,13 +2,13 @@import marimo-__generated_with = "0.5.0"+__generated_with = "0.8.14"app = marimo.App()@app.celldef __(mo):- mo.md("# Horizontal")+ mo.md("""# Horizontal""")return@@ -26,7 +26,7 @@ def __(mo):@app.celldef __(mo):- mo.md("-----")+ mo.md("""-----""")return@@ -58,7 +58,7 @@ def __(mo):@app.celldef __(mo):- mo.md("# Vertical")+ mo.md("""# Vertical""")return@@ -77,7 +77,7 @@ def __(mo):@app.celldef __(mo):- mo.md("-----")+ mo.md("""-----""")returndiff --git a/marimo/_smoke_tests/output.py b/marimo/_smoke_tests/output.pyindex 00c47c145a..000ccd5e5c 100644--- a/marimo/_smoke_tests/output.py+++ b/marimo/_smoke_tests/output.py@@ -2,7 +2,7 @@import marimo-__generated_with = "0.6.0"+__generated_with = "0.8.14"app = marimo.App()@@ -34,7 +34,7 @@ def __(mo, time):@app.celldef __(mo):- mo.md("### Replace")+ mo.md("""### Replace""")return@@ -54,7 +54,7 @@ def __(loop_replace, mo):@app.celldef __(mo):- mo.md("### Append")+ mo.md("""### Append""")return@@ -74,7 +74,7 @@ def __(loop_append, mo):@app.celldef __(mo):- mo.md("### Clear")+ mo.md("""### Clear""")return@@ -96,7 +96,7 @@ def __(loop_append, mo):@app.celldef __(mo):- mo.md("### Sleep (stale)")+ mo.md("""### Sleep (stale)""")return@@ -111,6 +111,7 @@ def __(time):def __(mo):mo.output.append(mo.md("To be replaced."))mo.output.replace_at_index(mo.md("Replaced at index"), 0)+ returnif __name__ == "__main__":diff --git a/marimo/_smoke_tests/plain.py b/marimo/_smoke_tests/plain.pyindex 81d428b5a9..2a781dcaa7 100644--- a/marimo/_smoke_tests/plain.py+++ b/marimo/_smoke_tests/plain.py@@ -1,3 +1,11 @@+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "vega-datasets",+# "marimo",+# "polars",+# ]+# ///# Copyright 2024 Marimo. All rights reserved.import marimodiff --git a/marimo/_smoke_tests/pyg_walker.py b/marimo/_smoke_tests/pyg_walker.pyindex 0498132194..869e239e53 100644--- a/marimo/_smoke_tests/pyg_walker.py+++ b/marimo/_smoke_tests/pyg_walker.py@@ -1,7 +1,16 @@+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "pandas",+# "pygwalker",+# "marimo",+# ]+# ///# Copyright 2024 Marimo. All rights reserved.+import marimo-__generated_with = "0.7.5"+__generated_with = "0.8.14"app = marimo.App(width="medium")diff --git a/marimo/_smoke_tests/query_params.py b/marimo/_smoke_tests/query_params.pyindex 31ced8fad3..0ce38cf383 100644--- a/marimo/_smoke_tests/query_params.py+++ b/marimo/_smoke_tests/query_params.py@@ -1,7 +1,14 @@+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "marimo",+# ]+# ///# Copyright 2024 Marimo. All rights reserved.+import marimo-__generated_with = "0.3.4"+__generated_with = "0.8.14"app = marimo.App()@@ -68,11 +75,7 @@ def __(mo, query_params):@app.celldef __(mo):- mo.md(- """- You can also initialized with query params. Open this URL [/?foo=1&bar=2&bar=3&baz=4](/?foo=1&bar=2&bar=3&baz=4) and restart the kernel- """- )+ mo.md("""You can also initialized with query params. Open this URL [/?foo=1&bar=2&bar=3&baz=4](/?foo=1&bar=2&bar=3&baz=4) and restart the kernel""")returndiff --git a/marimo/_smoke_tests/routes.py b/marimo/_smoke_tests/routes.pyindex c5b4be8eb8..86bdb27adb 100644--- a/marimo/_smoke_tests/routes.py+++ b/marimo/_smoke_tests/routes.py@@ -1,3 +1,9 @@+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "marimo",+# ]+# ///# Copyright 2024 Marimo. All rights reserved.import marimodiff --git a/marimo/_smoke_tests/run_button.py b/marimo/_smoke_tests/run_button.pyindex 92e5629b31..ca9e90d0d6 100644--- a/marimo/_smoke_tests/run_button.py+++ b/marimo/_smoke_tests/run_button.py@@ -1,3 +1,9 @@+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "marimo",+# ]+# ///# Copyright 2024 Marimo. All rights reserved.import marimodiff --git a/marimo/_smoke_tests/scale.py b/marimo/_smoke_tests/scale.pyindex 06c5f45dbc..d9f533a458 100644--- a/marimo/_smoke_tests/scale.py+++ b/marimo/_smoke_tests/scale.py@@ -1,13 +1,20 @@+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "marimo",+# ]+# ///# Copyright 2024 Marimo. All rights reserved.+import marimo-__generated_with = "0.1.0"+__generated_with = "0.8.14"app = marimo.App()@app.celldef __(mo):- mo.md("# Scale")+ mo.md("""# Scale""")return@@ -134,36 +141,36 @@ def __():def __(mo):mo.md("""- ---+ ---- # h1 Heading- ## h2 Heading- ### h3 Heading- #### h4 Heading- ##### h5 Heading- ###### h6 Heading+ # h1 Heading+ ## h2 Heading+ ### h3 Heading+ #### h4 Heading+ ##### h5 Heading+ ###### h6 Heading- ## Emphasis+ ## Emphasis- **This is bold text**+ **This is bold text**- __This is bold text__+ __This is bold text__- *This is italic text*+ *This is italic text*- _This is italic text_+ _This is italic text_- ~~Strikethrough~~+ ~~Strikethrough~~- ## Blockquotes+ ## Blockquotes- > Blockquotes can also be nested...- >> ...by using additional greater-than signs right next to each other...- > > > ...or with spaces between arrows.- """+ > Blockquotes can also be nested...+ >> ...by using additional greater-than signs right next to each other...+ > > > ...or with spaces between arrows.+ """)returndiff --git a/marimo/_smoke_tests/scripting.py b/marimo/_smoke_tests/scripting.pyindex 9b80ec375d..e35518ab06 100644--- a/marimo/_smoke_tests/scripting.py+++ b/marimo/_smoke_tests/scripting.py@@ -1,8 +1,14 @@+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "marimo",+# ]+# ///# Copyright 2024 Marimo. All rights reserved.import marimo-__generated_with = "0.6.0"+__generated_with = "0.8.14"app = marimo.App()@@ -14,7 +20,7 @@ def __():@app.celldef __(mo):- mo.md("hello")+ mo.md("""hello""")returndiff --git a/marimo/_smoke_tests/sql.py b/marimo/_smoke_tests/sql.pyindex 642020fe3c..c37c26163f 100644--- a/marimo/_smoke_tests/sql.py+++ b/marimo/_smoke_tests/sql.py@@ -1,8 +1,17 @@+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "duckdb",+# "vega-datasets",+# "marimo",+# "altair",+# ]+# ///# Copyright 2024 Marimo. All rights reserved.import marimo-__generated_with = "0.6.25"+__generated_with = "0.8.14"app = marimo.App(width="medium")@@ -17,7 +26,7 @@ def __():@app.cell(hide_code=True)def __(mo):- mo.md("## Cars")+ mo.md("""## Cars""")return@@ -56,7 +65,7 @@ def __(alt, df, mo):@app.cell(hide_code=True)def __(mo):- mo.md("## Airports")+ mo.md("""## Airports""")return@@ -84,7 +93,7 @@ def __(less_airports):@app.celldef __(mo):- mo.md("## Google Sheets")+ mo.md("""## Google Sheets""")return@@ -126,7 +135,7 @@ def __(job_title, mo, sheet):@app.cell(hide_code=True)def __(mo):- mo.md("Debug")+ mo.md("""Debug""")returndiff --git a/marimo/_smoke_tests/sql/duckdb_tokenize.py b/marimo/_smoke_tests/sql/duckdb_tokenize.pyindex 7819a4daf4..29141b6a8d 100644--- a/marimo/_smoke_tests/sql/duckdb_tokenize.py+++ b/marimo/_smoke_tests/sql/duckdb_tokenize.py@@ -1,3 +1,10 @@+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "duckdb",+# "marimo",+# ]+# ///# Copyright 2024 Marimo. All rights reserved.import marimodiff --git a/marimo/_smoke_tests/sql/limits.py b/marimo/_smoke_tests/sql/limits.pyindex 7cf4e605fa..0ad1565e65 100644--- a/marimo/_smoke_tests/sql/limits.py+++ b/marimo/_smoke_tests/sql/limits.py@@ -1,3 +1,9 @@+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "marimo",+# ]+# ///# Copyright 2024 Marimo. All rights reserved.import marimodiff --git a/marimo/_smoke_tests/state.py b/marimo/_smoke_tests/state.pyindex 98a50750fe..7fdb7d62cb 100644--- a/marimo/_smoke_tests/state.py+++ b/marimo/_smoke_tests/state.py@@ -1,3 +1,9 @@+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "marimo",+# ]+# ///# Copyright 2024 Marimo. All rights reserved.import marimodiff --git a/marimo/_smoke_tests/status.py b/marimo/_smoke_tests/status.pyindex 0c3e6eafe5..78fcee5501 100644--- a/marimo/_smoke_tests/status.py+++ b/marimo/_smoke_tests/status.py@@ -1,3 +1,9 @@+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "marimo",+# ]+# ///# Copyright 2024 Marimo. All rights reserved.import marimodiff --git a/marimo/_smoke_tests/stdin.py b/marimo/_smoke_tests/stdin.pyindex 53edb2b7d9..89a9ebdf3c 100644--- a/marimo/_smoke_tests/stdin.py+++ b/marimo/_smoke_tests/stdin.py@@ -1,3 +1,9 @@+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "marimo",+# ]+# ///# Copyright 2024 Marimo. All rights reserved.import marimodiff --git a/marimo/_smoke_tests/stop.py b/marimo/_smoke_tests/stop.pyindex 659bcf2a8a..bf42ce462c 100644--- a/marimo/_smoke_tests/stop.py+++ b/marimo/_smoke_tests/stop.py@@ -1,3 +1,9 @@+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "marimo",+# ]+# ///# Copyright 2024 Marimo. All rights reserved.import marimodiff --git a/marimo/_smoke_tests/table_urls.py b/marimo/_smoke_tests/table_urls.pyindex 7d829edf32..67786a9151 100644--- a/marimo/_smoke_tests/table_urls.py+++ b/marimo/_smoke_tests/table_urls.py@@ -1,3 +1,9 @@+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "marimo",+# ]+# ///# Copyright 2024 Marimo. All rights reserved.import marimodiff --git a/marimo/_smoke_tests/tables/booleans.py b/marimo/_smoke_tests/tables/booleans.pyindex 6c7ff87fbd..1f6c173d41 100644--- a/marimo/_smoke_tests/tables/booleans.py+++ b/marimo/_smoke_tests/tables/booleans.py@@ -3,6 +3,7 @@# dependencies = [# "marimo",# "pandas",+# "polars",# ]# ///diff --git a/marimo/_smoke_tests/tables/dictionary_table.py b/marimo/_smoke_tests/tables/dictionary_table.pyindex 97deb18933..f304fb8da5 100644--- a/marimo/_smoke_tests/tables/dictionary_table.py+++ b/marimo/_smoke_tests/tables/dictionary_table.py@@ -1,3 +1,9 @@+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "marimo",+# ]+# ///# Copyright 2024 Marimo. All rights reserved.import marimodiff --git a/marimo/_smoke_tests/tables/server_pagination.py b/marimo/_smoke_tests/tables/server_pagination.pyindex 8d66fd877c..be32abf907 100644--- a/marimo/_smoke_tests/tables/server_pagination.py+++ b/marimo/_smoke_tests/tables/server_pagination.py@@ -1,3 +1,10 @@+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "vega-datasets",+# "marimo",+# ]+# ///# Copyright 2024 Marimo. All rights reserved.import marimodiff --git a/marimo/_smoke_tests/theming/altair_theme.py b/marimo/_smoke_tests/theming/altair_theme.pyindex ccc73eed1a..29d540731b 100644--- a/marimo/_smoke_tests/theming/altair_theme.py+++ b/marimo/_smoke_tests/theming/altair_theme.py@@ -2,6 +2,7 @@# requires-python = ">=3.11"# dependencies = [# "altair",+# "marimo",# ]# ///diff --git a/marimo/_smoke_tests/theming/apply_theme.py b/marimo/_smoke_tests/theming/apply_theme.pyindex 55dcfce5c1..294c1381ec 100644--- a/marimo/_smoke_tests/theming/apply_theme.py+++ b/marimo/_smoke_tests/theming/apply_theme.py@@ -1,3 +1,18 @@+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "seaborn",+# "matplotlib",+# "holoviews",+# "bokeh",+# "vega-datasets",+# "altair",+# "plotly",+# "marimo",+# "pandas",+# "numpy",+# ]+# ///import marimo__generated_with = "0.8.3"diff --git a/marimo/_smoke_tests/third_party/altair_example.py b/marimo/_smoke_tests/third_party/altair_example.pyindex 49e91e9381..ba1f96e03f 100644--- a/marimo/_smoke_tests/third_party/altair_example.py+++ b/marimo/_smoke_tests/third_party/altair_example.py@@ -1,4 +1,11 @@-# Copyright 2024 Marimo. All rights reserved.+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "marimo",+# "vega-datasets",+# "altair",+# ]+# ///import marimodiff --git a/marimo/_smoke_tests/third_party/holoviews_example.py b/marimo/_smoke_tests/third_party/holoviews_example.pyindex afebdb8c64..1978cfbf69 100644--- a/marimo/_smoke_tests/third_party/holoviews_example.py+++ b/marimo/_smoke_tests/third_party/holoviews_example.py@@ -1,4 +1,15 @@-# Copyright 2024 Marimo. All rights reserved.+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "numpy",+# "holoviews",+# "pandas",+# "marimo",+# "hvplot",+# "bokeh",+# "polars",+# ]+# ///import marimodiff --git a/marimo/_smoke_tests/third_party/ipython_display.py b/marimo/_smoke_tests/third_party/ipython_display.pyindex 2ebe4cfe68..3dd72a94dd 100644--- a/marimo/_smoke_tests/third_party/ipython_display.py+++ b/marimo/_smoke_tests/third_party/ipython_display.py@@ -1,3 +1,10 @@+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "ipython",+# "marimo",+# ]+# ///# Copyright 2024 Marimo. All rights reserved.import marimodiff --git a/marimo/_smoke_tests/third_party/pandas_example.py b/marimo/_smoke_tests/third_party/pandas_example.pyindex 797b4cbbb6..eed11ae821 100644--- a/marimo/_smoke_tests/third_party/pandas_example.py+++ b/marimo/_smoke_tests/third_party/pandas_example.py@@ -1,4 +1,10 @@-# Copyright 2024 Marimo. All rights reserved.+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "pandas",+# "numpy",+# ]+# ///import marimo__generated_with = "0.1.0"diff --git a/marimo/_smoke_tests/third_party/plotly_example.py b/marimo/_smoke_tests/third_party/plotly_example.pyindex b151fb051b..ccb6360cdb 100644--- a/marimo/_smoke_tests/third_party/plotly_example.py+++ b/marimo/_smoke_tests/third_party/plotly_example.py@@ -1,13 +1,20 @@-# Copyright 2024 Marimo. All rights reserved.+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "plotly",+# "pandas",+# ]+# ///+import marimo-__generated_with = "0.1.51"+__generated_with = "0.8.14"app = marimo.App(width="full")@app.celldef __(mo):- mo.md("# Plotly Express Chart")+ mo.md("""# Plotly Express Chart""")return@@ -59,7 +66,7 @@ def __(mo, plot):@app.celldef __(mo):- mo.md("# Plotly Graph Objects Chart")+ mo.md("""# Plotly Graph Objects Chart""")return@@ -121,7 +128,7 @@ def __(mo, plot2):@app.celldef __(mo):- mo.md("# Re-rendering Chart")+ mo.md("""# Re-rendering Chart""")return@@ -166,7 +173,7 @@ def __(mo, plot3):@app.celldef __(mo):- mo.md("# 3D Chart")+ mo.md("""# 3D Chart""")returndiff --git a/marimo/_smoke_tests/third_party/rich_example.py b/marimo/_smoke_tests/third_party/rich_example.pyindex 4a2d3472a9..cd54a37b0b 100644--- a/marimo/_smoke_tests/third_party/rich_example.py+++ b/marimo/_smoke_tests/third_party/rich_example.py@@ -1,4 +1,10 @@-# Copyright 2024 Marimo. All rights reserved.+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "marimo",+# "rich",+# ]+# ///import marimo__generated_with = "0.1.88"diff --git a/marimo/_smoke_tests/third_party/seaborn_example.py b/marimo/_smoke_tests/third_party/seaborn_example.pyindex 27bda3b0aa..d0320f3670 100644--- a/marimo/_smoke_tests/third_party/seaborn_example.py+++ b/marimo/_smoke_tests/third_party/seaborn_example.py@@ -1,3 +1,9 @@+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "seaborn",+# ]+# ///# Copyright 2024 Marimo. All rights reserved.import marimodiff --git a/tests/_output/formatters/test_formatters.py b/tests/_output/formatters/test_formatters.pyindex b9cc55fa3b..e65a7bb899 100644--- a/tests/_output/formatters/test_formatters.py+++ b/tests/_output/formatters/test_formatters.py@@ -3,6 +3,7 @@ from __future__ import annotationsimport importlibimport os.pathimport sys+from typing import Anyfrom unittest.mock import Mock, patchimport pytest@@ -158,6 +159,7 @@ def test_repr_markdown():)def test_repr_latex():class ReprLatex:def _repr_latex_(self):@@ -274,7 +276,21 @@ def test_repr_mimebundle():assert formattermime, content = formatter(obj)assert mime == "application/vnd.marimo+mimebundle"- assert content == {- "application/json": {"message": "Hello, World!"},- "text/plain": "Hello, World!",- }+ assert content == {"application/json": {"message": "Hello, World!"}}+++def test_repr_mimebundle_with_exclude():+ class ReprMimeBundle:+ def _repr_mimebundle_(self, include: Any = None, exclude: Any = None):+ del include, exclude+ return {+ "application/json": {"message": "Hello, World!"},+ "text/plain": "Hello, World!",+ }++ obj = ReprMimeBundle()+ formatter = get_formatter(obj)+ assert formatter+ mime, content = formatter(obj)+ assert mime == "application/vnd.marimo+mimebundle"+ assert content == {"application/json": {"message": "Hello, World!"}}diff --git a/tests/_plugins/ui/_impl/test_altair_chart.py b/tests/_plugins/ui/_impl/test_altair_chart.pyindex ce799088b0..874e6fc058 100644--- a/tests/_plugins/ui/_impl/test_altair_chart.py+++ b/tests/_plugins/ui/_impl/test_altair_chart.py@@ -14,6 +14,7 @@ from marimo._plugins.ui._impl.altair_chart import (ChartDataType,ChartSelection,_filter_dataframe,+ _has_geoshape,_parse_spec,)from marimo._runtime.runtime import Kernel@@ -366,3 +367,51 @@ def test_parse_spec_geopandas() -> None:)spec = _parse_spec(chart)snapshot("parse_spec_geopandas.txt", json.dumps(spec, indent=2))++[email protected](not HAS_DEPS, reason="optional dependencies not installed")+def test_has_geoshape() -> None:+ import altair as alt++ chart_with_geoshape = alt.Chart().mark_geoshape()+ assert _has_geoshape(chart_with_geoshape) is True++ chart_with_geoshape = alt.Chart().mark_geoshape(stroke="black")+ assert _has_geoshape(chart_with_geoshape) is True++ chart_without_geoshape = alt.Chart().mark_bar()+ assert _has_geoshape(chart_without_geoshape) is False++[email protected](not HAS_DEPS, reason="optional dependencies not installed")+def test_no_selection_pandas() -> None:+ import altair as alt+ import pandas as pd++ data = pd.DataFrame({"values": [1, 2, 3]})+ chart = altair_chart.altair_chart(+ alt.Chart(data).mark_point().encode(x="values:Q")+ )+ assert isinstance(chart._value, pd.DataFrame)+ assert len(chart._value) == 0+ selected_value = chart._convert_value({})+ assert isinstance(selected_value, pd.DataFrame)+ selected_value = chart._convert_value(None)+ assert isinstance(selected_value, pd.DataFrame)++[email protected](not HAS_DEPS, reason="optional dependencies not installed")+def test_no_selection_polars() -> None:+ import altair as alt+ import polars as pl++ data = pl.DataFrame({"values": [1, 2, 3]})+ chart = altair_chart.altair_chart(+ alt.Chart(data).mark_point().encode(x="values:Q")+ )+ assert isinstance(chart._value, pl.DataFrame)+ assert len(chart._value) == 0+ selected_value = chart._convert_value({})+ assert isinstance(selected_value, pl.DataFrame)+ selected_value = chart._convert_value(None)+ assert isinstance(selected_value, pl.DataFrame)