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: add fallback to csv for col summaries (#5871)

Shahmir Varqha56e801677bfe
diff --git a/frontend/src/plugins/impl/DataTablePlugin.tsx b/frontend/src/plugins/impl/DataTablePlugin.tsx
index 279da89a6c..b00f017d9e 100644
--- a/frontend/src/plugins/impl/DataTablePlugin.tsx
+++ b/frontend/src/plugins/impl/DataTablePlugin.tsx
@@ -730,6 +730,8 @@ const DataTableComponent = ({
return ColumnChartSpecModel.EMPTY;
}
const fieldTypesWithoutExternalTypes = toFieldTypes(fieldTypes);
+ const performantCharts = getFeatureFlag("performant_table_charts");
+
return new ColumnChartSpecModel(
columnSummaries.data || [],
fieldTypesWithoutExternalTypes,
@@ -737,8 +739,9 @@ const DataTableComponent = ({
columnSummaries.bin_values,
columnSummaries.value_counts,
{
- includeCharts: Boolean(columnSummaries.data),
- usePreComputedValues: getFeatureFlag("performant_table_charts"),
+ // If performant charts are enabled, it does not use columnSummaries.data
+ includeCharts: performantCharts || Boolean(columnSummaries.data),
+ usePreComputedValues: performantCharts,
},
);
}, [fieldTypes, columnSummaries]);
diff --git a/marimo/_plugins/ui/_impl/table.py b/marimo/_plugins/ui/_impl/table.py
index 0e0264afd7..316cd5e8c7 100644
--- a/marimo/_plugins/ui/_impl/table.py
+++ b/marimo/_plugins/ui/_impl/table.py
@@ -1001,16 +1001,35 @@ class table(
We return a URL instead of the data directly
so the browser can cache requests
"""
- try:
- data_url = mo_data.arrow(table_manager.to_arrow_ipc()).url
- return data_url, "arrow"
- except NotImplementedError:
+ if DependencyManager.pyarrow.has():
try:
- data_url = mo_data.csv(table_manager.to_csv({})).url
- return data_url, "csv"
- except ValueError:
- data_url = mo_data.json(table_manager.to_json({})).url
- return data_url, "json"
+ data_url = mo_data.arrow(table_manager.to_arrow_ipc()).url
+ return data_url, "arrow"
+ except NotImplementedError:
+ LOGGER.debug(
+ "Arrow export not implemented, falling back to CSV."
+ )
+ except Exception as e:
+ LOGGER.error("Unexpected error exporting Arrow: %s", e)
+
+ # Try CSV
+ try:
+ data_url = mo_data.csv(table_manager.to_csv({})).url
+ return data_url, "csv"
+ except (ValueError, NotImplementedError):
+ LOGGER.debug("CSV export failed, falling back to JSON.")
+ except Exception as e:
+ LOGGER.error("Unexpected error exporting CSV: %s", e)
+
+ # Fallback to JSON
+ try:
+ data_url = mo_data.json(table_manager.to_json({})).url
+ return data_url, "json"
+ except Exception as e:
+ LOGGER.error(
+ "Failed to export table data as Arrow, CSV, or JSON: %s", e
+ )
+ raise
def _get_data_url(self, args: EmptyArgs) -> GetDataUrlResponse:
"""Get the data URL for the entire table. Used for charting."""
diff --git a/marimo/_plugins/ui/_impl/tables/polars_table.py b/marimo/_plugins/ui/_impl/tables/polars_table.py
index 942e2c9961..725716b24b 100644
--- a/marimo/_plugins/ui/_impl/tables/polars_table.py
+++ b/marimo/_plugins/ui/_impl/tables/polars_table.py
@@ -154,15 +154,6 @@ class PolarsTableManagerFactory(TableManagerFactory):
result, column
)
converted_columns.append(column.name)
- # https://github.com/pola-rs/polars/issues/23459
- elif isinstance(dtype, pl.List) and isinstance(
- dtype.inner, (pl.Enum, pl.Categorical)
- ):
- # Convert each element in the list to a string
- result = result.with_columns(
- pl.col(column.name).cast(pl.List(pl.String))
- )
- converted_columns.append(column.name)
if converted_columns:
LOGGER.info(
diff --git a/pyproject.toml b/pyproject.toml
index 7b2bf853ba..77ac13e11b 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -242,7 +242,7 @@ extra-dependencies = [
"pyarrow>=19.0.1",
"pyarrow_hotfix",
"altair>=5.4.0",
- "polars>=1.30.0",
+ "polars>=1.32.0",
"sqlglot>=23.4",
"sqlalchemy>=2.0.40",
"pyiceberg>=0.9.0",
diff --git a/tests/_plugins/ui/_impl/tables/test_polars_table.py b/tests/_plugins/ui/_impl/tables/test_polars_table.py
index 6a40948f8d..6f66081ae5 100644
--- a/tests/_plugins/ui/_impl/tables/test_polars_table.py
+++ b/tests/_plugins/ui/_impl/tables/test_polars_table.py
@@ -957,45 +957,9 @@ class TestPolarsTableManagerFactory(unittest.TestCase):
assert json_data[1]["A"] == "9007199254740992"
assert json_data[1]["B"] == "-9007199254740992"
- def test_to_json_enum_list(self) -> None:
- import polars as pl
-
- data = {"A": [["A", "B", "C"], ["A", "B", "C"], ["A", "B", "C"]]}
-
- data_enum = pl.DataFrame(
- data, schema={"A": pl.List(pl.Enum(categories=["A", "B", "C"]))}
- )
- manager = self.factory.create()(data_enum)
- json_data = json.loads(manager.to_json())
- assert json_data[0]["A"] == ["A", "B", "C"]
- assert json_data[1]["A"] == ["A", "B", "C"]
- assert json_data[2]["A"] == ["A", "B", "C"]
-
- data_categorical = pl.DataFrame(
- data, schema={"A": pl.List(pl.Categorical())}
- )
- manager = self.factory.create()(data_categorical)
- json_data = json.loads(manager.to_json())
- assert json_data[0]["A"] == ["A", "B", "C"]
- assert json_data[1]["A"] == ["A", "B", "C"]
- assert json_data[2]["A"] == ["A", "B", "C"]
-
- def test_to_json_enum_list_not_supported(self) -> None:
- # When this is supported, we can remove the casting to string
- import polars as pl
-
- data = {"A": [["A", "B", "C"], ["A", "B", "C"], ["A", "B", "C"]]}
-
- data_enum = pl.DataFrame(
- data, schema={"A": pl.List(pl.Enum(categories=["A", "B", "C"]))}
- )
- with pytest.raises(pl.exceptions.PanicException):
- data_enum.write_json()
-
- data_list = pl.DataFrame(data, schema={"A": pl.List(pl.Categorical())})
- with pytest.raises(pl.exceptions.PanicException):
- data_list.write_json()
-
+ @pytest.mark.xfail(
+ reason="Polars does not support writing binary data to JSON"
+ )
def test_to_json_binary(self) -> None:
# Remove casting to string once binary is supported
import polars as pl
@@ -1008,5 +972,4 @@ class TestPolarsTableManagerFactory(unittest.TestCase):
}
)
- with pytest.raises(pl.exceptions.PanicException):
- data.write_json()
+ data.write_json()