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: fall back to CSV for Altair charts without pyarrow (#10855)
Myles Scolnick39d28c76e3ca
diff --git a/marimo/_plugins/ui/_impl/tables/pandas_table.py b/marimo/_plugins/ui/_impl/tables/pandas_table.pyindex 0b13786814..7521f406e5 100644--- a/marimo/_plugins/ui/_impl/tables/pandas_table.py+++ b/marimo/_plugins/ui/_impl/tables/pandas_table.py@@ -11,6 +11,7 @@ import narwhals.stable.v2 as nwfrom marimo import _loggersfrom marimo._data.models import ExternalDataType+from marimo._dependencies.dependencies import DependencyManagerfrom marimo._messaging.msgspec_encoder import enc_hookfrom marimo._output.data.data import sanitize_json_bigintfrom marimo._plugins.ui._impl.tables.format import (@@ -402,6 +403,11 @@ class PandasTableManagerFactory(TableManagerFactory):return pd.api.types.infer_dtype(self._original_data[column])def to_arrow_ipc(self) -> bytes:+ if not DependencyManager.pyarrow.has():+ raise NotImplementedError(+ "pyarrow is required for Arrow serialization"+ )+import pyarrow as padf = self._original_datadiff --git a/tests/_plugins/ui/_impl/charts/test_altair_transformers.py b/tests/_plugins/ui/_impl/charts/test_altair_transformers.pyindex 9634f00fa8..31fbdb0ed5 100644--- a/tests/_plugins/ui/_impl/charts/test_altair_transformers.py+++ b/tests/_plugins/ui/_impl/charts/test_altair_transformers.py@@ -3,6 +3,7 @@ from __future__ import annotationsimport base64import datetimeimport json+import sysfrom typing import TYPE_CHECKINGfrom unittest.mock import MagicMock, patch@@ -247,6 +248,34 @@ def test_to_marimo_arrow(df: IntoDataFrame):assert result["format"] == {"type": "arrow"}[email protected](not HAS_DEPS, reason="optional dependencies not installed")+ "df",+ create_dataframes(+ {"A": [1, 2, 3], "B": ["a", "b", "c"]}, include=SUPPORTS_ARROW_IPC+ ),+)+def test_to_marimo_arrow_without_pyarrow(df: IntoDataFrame):+ import pandas as pd++ with (+ patch.object(DependencyManager.pyarrow, "has", return_value=False),+ patch.dict(sys.modules, {"pyarrow": None}),+ patch(+ "marimo._plugins.ui._impl.charts.altair_transformer.LOGGER.warning",+ side_effect=OSError("[WinError 1] Incorrect function"),+ ) as warning,+ ):+ result = _to_marimo_arrow(df)++ if isinstance(df, pd.DataFrame):+ assert result == _to_marimo_csv(df)+ else:+ # Polars can serialize Arrow IPC without pyarrow.+ assert result["format"] == {"type": "arrow"}+ warning.assert_not_called()++@pytest.mark.skipif(not HAS_DEPS, reason="optional dependencies not installed")@pytest.mark.parametrize("df",diff --git a/tests/_plugins/ui/_impl/test_altair_chart.py b/tests/_plugins/ui/_impl/test_altair_chart.pyindex a64e5f1ebf..759fdee481 100644--- a/tests/_plugins/ui/_impl/test_altair_chart.py+++ b/tests/_plugins/ui/_impl/test_altair_chart.py@@ -912,6 +912,30 @@ def test_parse_spec_defaults_to_arrow() -> None:alt.data_transformers.enable(previous)[email protected]("pandas", "altair")+def test_altair_chart_without_pyarrow() -> None:+ import altair as alt+ import pandas as pd++ data = pd.DataFrame({"x": [1, 2, 3], "y": [4, 5, 6]})+ chart = alt.Chart(data).mark_line().encode(x="x:Q", y="y:Q")+ with (+ alt.data_transformers.enable("default"),+ unittest.mock.patch.object(+ DependencyManager.pyarrow, "has", return_value=False+ ),+ unittest.mock.patch.dict(sys.modules, {"pyarrow": None}),+ unittest.mock.patch(+ "marimo._plugins.ui._impl.charts.altair_transformer.LOGGER.warning",+ side_effect=OSError("[WinError 1] Incorrect function"),+ ) as warning,+ ):+ element = altair_chart(chart)++ assert element._component_args["spec"]["data"]["format"] == {"type": "csv"}+ warning.assert_not_called()++@pytest.mark.skipif(not HAS_DEPS or not DependencyManager.duckdb.has(),reason="optional dependencies not installed",