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 tests by casting enum to string for polars (#6936)
Shahmir Varqhaaffa1c9e7f36
diff --git a/marimo/_plugins/ui/_impl/tables/polars_table.py b/marimo/_plugins/ui/_impl/tables/polars_table.pyindex 058392d8f8..3c59580e44 100644--- a/marimo/_plugins/ui/_impl/tables/polars_table.py+++ b/marimo/_plugins/ui/_impl/tables/polars_table.py@@ -154,6 +154,15 @@ class PolarsTableManagerFactory(TableManagerFactory):result, column)converted_columns.append(column.name)+ # https://github.com/marimo-team/marimo/issues/5562+ 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/tests/_plugins/ui/_impl/tables/test_polars_table.py b/tests/_plugins/ui/_impl/tables/test_polars_table.pyindex a40ee4815a..1ebeb1535c 100644--- a/tests/_plugins/ui/_impl/tables/test_polars_table.py+++ b/tests/_plugins/ui/_impl/tables/test_polars_table.py@@ -982,3 +982,19 @@ class TestPolarsTableManagerFactory(unittest.TestCase):)data.write_json()++ 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()