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: data_editor corrupts float16 columns on edit (follow-up to #10211) (#10304)

Myles Scolnickac5f44e62a42
diff --git a/marimo/_plugins/ui/_impl/data_editor.py b/marimo/_plugins/ui/_impl/data_editor.py
index e74406f808..f24574c040 100644
--- a/marimo/_plugins/ui/_impl/data_editor.py
+++ b/marimo/_plugins/ui/_impl/data_editor.py
@@ -366,8 +366,13 @@ def _convert_value(
# If it's not a string or list, wrap it in a list
return [value]
else:
- LOGGER.warning(f"Unsupported dtype: {dtype}")
- return str(value)
+ # narwhals maps some pandas extension dtypes (notably
+ # float16) to nw.Unknown. Stringifying here would coerce the
+ # whole column to object; fall through to the original-value
+ # coercion below, which keeps the column numeric.
+ LOGGER.debug(
+ "Unhandled dtype %s; coercing from original value", dtype
+ )
if original_value is None:
return value
diff --git a/tests/_plugins/ui/_impl/test_data_editor.py b/tests/_plugins/ui/_impl/test_data_editor.py
index d375556426..1667183e7d 100644
--- a/tests/_plugins/ui/_impl/test_data_editor.py
+++ b/tests/_plugins/ui/_impl/test_data_editor.py
@@ -1015,6 +1015,17 @@ class TestConvertValue:
assert result == expected
assert isinstance(result, type(expected))
+ def test_convert_value_unknown_dtype_coerces_from_original(self):
+ """An Unknown dtype (e.g. pandas float16) must not stringify.
+
+ narwhals reports some pandas extension dtypes as nw.Unknown; the
+ conversion should fall back to the original value's type instead of
+ coercing the column to object/string.
+ """
+ result = _convert_value("5.5", 1.0, nw.Unknown)
+ assert result == 5.5
+ assert isinstance(result, float)
+
def test_convert_value_with_dtype_string(self):
"""Test String conversion with dtype."""
result = _convert_value(42, None, nw.String)