Skip to content

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.

docs: altair data-transformers (#869)

Myles Scolnick883b96f6de28
diff --git a/docs/api/plotting.md b/docs/api/plotting.md
index 00aa8b9ef7..f1e194879f 100644
--- a/docs/api/plotting.md
+++ b/docs/api/plotting.md
@@ -42,6 +42,27 @@ For more information about plotting, see the [plotting guide](../guides/plotting
.. autofunction:: marimo.ui.altair_chart
```
+### Performance and Data Transformers
+
+Altair has a concept of [data](https://altair-viz.github.io/user_guide/data_transformers.html) transformers, which can be used to improve performance.
+
+Such examples are:
+
+- pandas Dataframe has to be sanitized and serialized to JSON.
+- The rows of a Dataframe might need to be sampled or limited to a maximum number.
+- The Dataframe might be written to a `.csv` or `.json` file for performance reasons.
+
+By default, Altair uses the `default` data transformer, which is the slowest in marimo. It is limited to 5000 rows (although we increase this to `20_000` rows as marimo can handle this). This includes the data inside the HTML that is being sent over the network, which can also be limited by marimo's maximum message size.
+
+It is recommended to use the `marimo_csv` data transformer, which is the most performant and can handle the largest datasets: it converts the data to a CSV file which is smaller and can be sent over the network. This can handle up to +400,000 rows with no issues.
+
+When using `mo.ui.altair_chart`, we automatically set the data transformer to `marimo_csv` for you. If you are using Altair directly, you can set the data transformer using the following code:
+
+```python
+import altair as alt
+alt.data_transformers.enable('marimo_csv')
+```
+
## Reactive plots with Plotly
```{eval-rst}
diff --git a/marimo/_output/formatters/altair_formatters.py b/marimo/_output/formatters/altair_formatters.py
index 9d4892bdd9..0e1afd014a 100644
--- a/marimo/_output/formatters/altair_formatters.py
+++ b/marimo/_output/formatters/altair_formatters.py
@@ -28,7 +28,7 @@ class AltairFormatter(FormatterFactory):
# It is required to set this back to the default,
# since mo.ui.altair_chart sets it to 'marimo'
- if alt.data_transformers.active.startswith("marimo"):
+ if alt.data_transformers.active == "marimo":
# Re-enable with the previous options
alt.data_transformers.enable(
"default", **alt.data_transformers.options