Repository navigation
Fix Json.cast_storage double-encoding large_string and string_view columns - #8682
Merged
lhoestq merged 3 commits intoOct 5, 2026
Merged
Conversation
âĶlumns Json.cast_storage only recognized pa.StringArray as already holding JSON text. large_string and string_view arrays fell through to the generic branch, which JSON-encoded every value again, so a column of JSON strings decoded back to plain strings instead of objects. This happens e.g. with Dataset.from_pandas(df, features=...) on pandas 3, whose str columns are converted to large_string.
This was referenced Sep 30, 2026
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
Contributor
Author
|
@lhoestq when you have a moment, could you approve the workflow runs and take a look? I merged current |
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.
Json.cast_storageonly treats apa.StringArrayas already holding JSON text.large_stringandstring_viewarrays are not subclasses of it, so they fall through to the generic branch and every value gets JSON-encoded a second time. The column then decodes back to plain strings instead of objects, and no error is raised.A common way to hit this is pandas 3, which converts a
strcolumn tolarge_string:cast_column("x", Json())on aValue("large_string")orValue("string_view")column has the same problem.The fix checks the Arrow type with
pa.types.is_string/is_large_string/is_string_viewin place of theisinstancecheck. Strings that are not valid JSON are still encoded as JSON strings, as before.Tests:
test_json_cast_storage_from_strings, parametrized over the three string types, andtest_dataset_cast_large_string_column_to_json. Before the fix, thelarge_stringandstring_viewcases fail. With the fix,tests/featurespasses (394 passed, 129 skipped) and so do the Json tests intests/test_arrow_dataset.py(pandas 3.0.6, pyarrow 25.0.1).ClassLabel.cast_storagehas the sameisinstance(storage, pa.StringArray)check. That one is tracked separately in #8681, so this PR leaves it alone.