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: to_json for pandas uuid (#4904)
Myles Scolnick9169caa8f697
diff --git a/marimo/_plugins/ui/_impl/tables/pandas_table.py b/marimo/_plugins/ui/_impl/tables/pandas_table.pyindex 470b456fef..813e3a1ecb 100644--- a/marimo/_plugins/ui/_impl/tables/pandas_table.py+++ b/marimo/_plugins/ui/_impl/tables/pandas_table.py@@ -98,7 +98,11 @@ class PandasTableManagerFactory(TableManagerFactory):exc_info=e,)return sanitize_json_bigint(- result.to_json(orient="records")+ result.to_json(+ orient="records",+ date_format="iso",+ default_handler=str,+ ))# Flatten row multi-index@@ -122,7 +126,11 @@ class PandasTableManagerFactory(TableManagerFactory):)return sanitize_json_bigint(- result.to_json(orient="records", date_format="iso")+ result.to_json(+ orient="records",+ date_format="iso",+ default_handler=str,+ ))def to_arrow_ipc(self) -> bytes:diff --git a/tests/_plugins/ui/_impl/tables/test_pandas_table.py b/tests/_plugins/ui/_impl/tables/test_pandas_table.pyindex e0826edc1b..a273cf67fb 100644--- a/tests/_plugins/ui/_impl/tables/test_pandas_table.py+++ b/tests/_plugins/ui/_impl/tables/test_pandas_table.py@@ -1083,3 +1083,33 @@ class TestPandasTableManager(unittest.TestCase):# Large integers should be converted to stringsassert json_data[1]["A"] == "9007199254740992"assert json_data[1]["B"] == "-9007199254740992"++ def test_to_json_uuid_encoding(self) -> None:+ import uuid++ import pandas as pd++ # Create data with UUIDs that might cause UTF-8 encoding issues+ data = pd.DataFrame(+ {+ "id": [+ uuid.UUID("00000000-0000-0000-0000-000000000000"),+ uuid.UUID("ffffffff-ffff-ffff-ffff-ffffffffffff"),+ uuid.UUID("123e4567-e89b-12d3-a456-426614174000"),+ ],+ "name": ["test1", "test2", "test3"],+ }+ )+ manager = self.factory.create()(data)++ # This should not raise any encoding errors+ json_data = json.loads(manager.to_json())++ # Verify the data was properly encoded+ assert len(json_data) == 3+ assert json_data[0]["id"] == "00000000-0000-0000-0000-000000000000"+ assert json_data[1]["id"] == "ffffffff-ffff-ffff-ffff-ffffffffffff"+ assert json_data[2]["id"] == "123e4567-e89b-12d3-a456-426614174000"+ assert json_data[0]["name"] == "test1"+ assert json_data[1]["name"] == "test2"+ assert json_data[2]["name"] == "test3"diff --git a/tests/_utils/test_inline_script_metadata.py b/tests/_utils/test_inline_script_metadata.pyindex 4bea07f989..8edf1fad16 100644--- a/tests/_utils/test_inline_script_metadata.py+++ b/tests/_utils/test_inline_script_metadata.py@@ -7,6 +7,7 @@ from marimo._utils.inline_script_metadata import (_pyproject_toml_to_requirements_txt,is_marimo_dependency,)+from marimo._utils.platform import is_windowsfrom marimo._utils.scripts import read_pyproject_from_script@@ -135,6 +136,7 @@ def test_pyproject_toml_to_requirements_txt_with_url_sources():][email protected](is_windows(), reason="only testing posix paths")def test_pyproject_toml_to_requirements_txt_with_local_path():pyproject = {"dependencies": [