Repository navigation
fix: data_editor corrupts float16 columns on edit (follow-up to #10211) - #10304
Merged
Merged
Conversation
… columns on edit narwhals maps some pandas extension dtypes (notably float16) to nw.Unknown, so _convert_value fell through to `str(value)`, coercing the whole column to object. #10211 fixed int8/uint8/float32 but float16 still degraded — its own dtype-preservation test was red on main. Fall through to the existing original-value coercion for Unknown dtypes instead of stringifying, keeping numeric columns numeric.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
kirangadhave
approved these changes
Jul 23, 2026
Comment on lines
+369
to
378
| # 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 |
Comment on lines
+1018
to
+1027
| 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) |
williambdean
pushed a commit
to williambdean/marimo
that referenced
this pull request
Sep 6, 2026
…o-team#10211) (marimo-team#10304) **This pull request was authored by a coding agent.** ## What / why Editing a cell in a **pandas `float16`** column silently corrupts the whole column: the edited value is stored as a string and the column dtype flips to `object`. ```python import pandas as pd from marimo._plugins.ui._impl.data_editor import apply_edits df = pd.DataFrame({"a": pd.array([1.0, 2.0, 3.0], dtype="float16")}) apply_edits(df, {"edits": [{"rowIdx": 0, "columnId": "a", "value": "5.5"}]}) # before: dtype object, values ['5.5', 2.0, 3.0] (corrupted) # after: dtype float16-compatible numeric, values [5.5, 2.0, 3.0] ``` marimo-team#10211 addressed `int8`/`uint8`/`float32` by switching to `dtype.is_integer()` / `dtype.is_float()`, but `float16` still degrades: narwhals (2.x) has no `Float16`, so it reports pandas `float16` as `nw.Unknown`. Both predicate checks return `False` and `_convert_value` falls through to `return str(value)`. The dtype-preservation test the PR added for `float16` is currently **red on `main`**: ``` FAILED tests/_plugins/ui/_impl/test_data_editor.py::test_apply_edits_dataframe_small_width_numeric_preserves_dtype[float16] ``` ## Fix For an unsupported/`Unknown` dtype, fall through to the existing original-value coercion (`_convert_value` already handles `int`/`float`/`str`/…) instead of stringifying. For a numeric column the original value is a Python `float`/`int`, so the edit stays numeric. This is a superset fix — any dtype narwhals can't classify but whose values are numeric now round-trips correctly. ## Tests - The previously-failing `test_apply_edits_dataframe_small_width_numeric_preserves_dtype[float16]` now passes. - Added `test_convert_value_unknown_dtype_coerces_from_original`, which pins the fall-through directly against `nw.Unknown` (independent of narwhals' evolving float16 mapping). - `pytest tests/_plugins/ui/_impl/test_data_editor.py` → 107 passed; `ruff check`/`ruff format` clean. Follow-up to marimo-team#10211.
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request was authored by a coding agent.
What / why
Editing a cell in a pandas
float16column silently corrupts the whole column: the edited value is stored as a string and the column dtype flips toobject.#10211 addressed
int8/uint8/float32by switching todtype.is_integer()/dtype.is_float(), butfloat16still degrades: narwhals (2.x) has noFloat16, so it reports pandasfloat16asnw.Unknown. Both predicate checks returnFalseand_convert_valuefalls through toreturn str(value). The dtype-preservation test the PR added forfloat16is currently red onmain:Fix
For an unsupported/
Unknowndtype, fall through to the existing original-value coercion (_convert_valuealready handlesint/float/str/…) instead of stringifying. For a numeric column the original value is a Pythonfloat/int, so the edit stays numeric. This is a superset fix — any dtype narwhals can't classify but whose values are numeric now round-trips correctly.Tests
test_apply_edits_dataframe_small_width_numeric_preserves_dtype[float16]now passes.test_convert_value_unknown_dtype_coerces_from_original, which pins the fall-through directly againstnw.Unknown(independent of narwhals' evolving float16 mapping).pytest tests/_plugins/ui/_impl/test_data_editor.py→ 107 passed;ruff check/ruff formatclean.Follow-up to #10211.