fix(table): preserve null extension-array values in JSON (#10299) - #10326
fix(table): preserve null extension-array values in JSON (#10299)#10326hsusul wants to merge 1 commit into
Conversation
|
I have read the CLA Document and I hereby sign the CLA |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
All contributors have signed the CLA ✍️ ✅ |
I have read the CLA Document and I hereby sign the CLA |
|
recheck |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
tests/_plugins/ui/_impl/tables/test_pandas_table.py:2373
- The expected string for the non-missing pint value is hard-coded ("1.0 meter"), which can vary across pint/pint-pandas versions and formatting. To avoid a brittle test, derive the expected string from pint-pandas (like test_to_json_str_pint_pandas_series does) and only hard-code the missing value as None.
manager = self.factory.create()(df)
json_data = json.loads(manager.to_json_str())
assert json_data == [{"length": "1.0 meter"}, {"length": None}]
| expected = [{"value": value} for value in series.astype(str)] | ||
| assert json_data == expected | ||
|
|
||
| @pytest.mark.requires("pint_pandas") |
There was a problem hiding this comment.
this test will never run, because we don't have pint or pint_pandas listed anywhere in our deps. Same with any other tests marked as requires pint or pint_pandas.
The test should create a new masked extension type within test scope and test against that. None of the new code is pint specific.
This pull request was authored by a coding agent.
📝 Summary
Closes #10299
Problem
When a pandas DataFrame column contains an extension array (such as
pint-pandas) with missing values (pd.NA,None,np.nan),PandasTableManager._to_json_strcalls_extension_column_needs_stringify(result[col])and unconditionally performsresult[col] = result[col].astype(str). This stringifies missing cells into literal text like"<NA> meter"(or"nan") instead of JSONnull.Fix
Convert valid non-missing cells in extension columns to string (
astype(str)), while using.astype(object).where(series.notna(), None)so missing entries remainNoneand serialize to JSONnullas expected.📋 Pre-Review Checklist
✅ Merge Checklist
Testing
uv run --group test pytest tests/_plugins/ui/_impl/tables/test_pandas_table.py— Passed (122 passed).uv run ruff check marimo/ tests/— Passed with 0 errors.uv run ruff format --check marimo/ tests/— Passed with 0 issues.