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.

fix: DatetimeTZDtype serialization (#631)

Myles Scolnick654a793863d7
diff --git a/marimo/_plugins/core/json_encoder.py b/marimo/_plugins/core/json_encoder.py
index 5e084c1310..26d98df200 100644
--- a/marimo/_plugins/core/json_encoder.py
+++ b/marimo/_plugins/core/json_encoder.py
@@ -37,6 +37,8 @@ class WebComponentEncoder(JSONEncoder):
return obj.to_list()
elif isinstance(obj, pd.Timestamp):
return str(obj)
+ elif isinstance(obj, pd.DatetimeTZDtype):
+ return str(obj)
# Handle MIME objects
if hasattr(obj, "_mime_"):
diff --git a/marimo/_plugins/ui/_impl/altair_chart.py b/marimo/_plugins/ui/_impl/altair_chart.py
index 3c369fefab..5ab57c2f5b 100644
--- a/marimo/_plugins/ui/_impl/altair_chart.py
+++ b/marimo/_plugins/ui/_impl/altair_chart.py
@@ -131,6 +131,10 @@ class altair_chart(UIElement[ChartSelection, "pd.DataFrame"]):
Use `mo.ui.altair_chart` to make Altair charts reactive: select chart data
with your cursor on the frontend, get them as a Pandas dataframe in Python!
+ For Polars DataFrames, you can convert to a Pandas DataFrame.
+ However the returned DataFrame will still be a Pandas DataFrame,
+ so you will need to convert back to a Polars DataFrame if you want.
+
**Example.**
```python
diff --git a/marimo/_plugins/ui/_impl/dataframes/dataframe.py b/marimo/_plugins/ui/_impl/dataframes/dataframe.py
index b283847de0..a779078f15 100644
--- a/marimo/_plugins/ui/_impl/dataframes/dataframe.py
+++ b/marimo/_plugins/ui/_impl/dataframes/dataframe.py
@@ -44,6 +44,11 @@ class GetColumnValuesResponse:
class dataframe(UIElement[Dict[str, Any], "pd.DataFrame"]):
"""
Run transformations on a DataFrame or series.
+ Currently only Pandas DataFrames are supported.
+
+ For Polars DataFrames, you can convert to a Pandas DataFrame.
+ However the returned DataFrame will still be a Pandas DataFrame,
+ so you will need to convert back to a Polars DataFrame if you want.
**Example.**
@@ -51,6 +56,10 @@ class dataframe(UIElement[Dict[str, Any], "pd.DataFrame"]):
dataframe = mo.ui.dataframe(data)
```
+ ```python
+ dataframe = mo.ui.dataframe(polars_df.to_pandas())
+ ```
+
**Attributes.**
- `value`: the transformed DataFrame or series