Repository navigation
Conversation
There was a problem hiding this comment.
For the new test around lines 4950–4967, please also cover the bytes branch through persistence. This concrete addition passes on 466fa31 and fails on parent json.py because the feature remains List(Json()) instead of binary (five selected cases pass on head, all five fail on parent):
def test_map_list_json_to_binary_survives_disk_roundtrip(tmp_path):
dataset = Dataset.from_dict(
{"messages": [[{"role": "user"}], [{"role": "assistant", "thinking": "next"}]]},
features=Features({"messages": List(Json())}),
)
payload = bytes([0, 255, 10, 65])
mapped = dataset.map(lambda batch: {"messages": [payload] * len(batch["messages"])}, batched=True)
assert mapped.features == Features({"messages": Value("binary")})
assert mapped.to_dict() == {"messages": [payload, payload]}
mapped.save_to_disk(tmp_path / "mapped")
restored = load_from_disk(tmp_path / "mapped")
assert restored.features == mapped.features
assert restored.to_dict() == mapped.to_dict()AI-assisted test suggestion, based on this PR reproducer; Windows CPU/local files, Ruff passed. No remote data, multiprocessing or full-suite claim.
There was a problem hiding this comment.
Added the disk round-trip regression in 93feaea. It maps two rows to distinct byte payloads, then checks that the feature is Value("binary") and the bytes are identical before and after save_to_disk and load_from_disk.
On macOS arm64 with PyArrow 24.0.0, all five focused regressions fail on upstream main and pass on the PR. The related Arrow, feature, and JSON suites finished with 1,156 passed and 45 skipped. make style and make quality passed. I also verified the binary round-trip with row and batch mapping using one and two processes on PyArrow 26.0.1.
Fixes #9324.
When
Dataset.map()replaces aList(Json())column with a string or a mapping, attempting to reuse the input feature can silently store a list of characters or keys. This was reported in an offline GRPO chat-template workflow. I reproduced the same failure with a local JSONL fixture containing messages with different key sets.The JSON encoder now rejects strings, bytes, and mappings at a list step. The Arrow writer then falls back to inferring the mapped column's actual type. This leaves list-like inputs on the existing encoding path.
Verification
mainand pass with this change on PyArrow 24.0.0.make qualitypassed.AI assistance was used to develop and test the patch.