Repository navigation
Add column metadata support to IterableDataset and IterableDatasetDict - #9153
LowmistLMT wants to merge 2 commits into
Conversation
|
Additional offline coverage on e4d7941: I exercised rename/select/remove/map(remove_columns=...) followed by actual Parquet export, both with explicit features and with features initially unknown. All 8 added cases pass, alongside the existing 23 tests (31 total). This checks the Arrow field metadata in the resulting file and source immutability. As a sensitivity check, removing only info=self._info.copy() from the Dataset construction inside IterableDataset.to_parquet makes all 8 added cases fail at the exported metadata assertion (empty metadata). This is mutation evidence, not a parent-revision comparison. No new defect found here. Suggested addition to tests/test_column_metadata.py (uses its existing imports): @pytest.mark.parametrize("known_features", [False, True])
@pytest.mark.parametrize("operation", ["rename", "select", "remove", "map_remove"])
def test_streaming_column_metadata_transform_parquet(tmp_path, known_features, operation):
rows = [{"distance": 1, "label": "x"}, {"distance": 2, "label": "y"}]
features = Dataset.from_list(rows).features if known_features else None
source = IterableDataset.from_generator(lambda: iter(rows), features=features).with_column_metadata(
{"distance": {"unit": "cm"}, "label": {"source": "manual"}}
)
if operation == "rename":
transformed = source.rename_column("distance", "position")
expected = {"position": {"unit": "cm"}, "label": {"source": "manual"}}
elif operation == "select":
transformed = source.select_columns("distance")
expected = {"distance": {"unit": "cm"}}
elif operation == "remove":
transformed = source.remove_columns("label")
expected = {"distance": {"unit": "cm"}}
else:
transformed = source.map(lambda row: {"position": row["distance"]}, remove_columns="distance")
expected = {"label": {"source": "manual"}}
assert transformed.info.column_metadata == expected
path = tmp_path / "transformed.parquet"
transformed.to_parquet(path)
schema = pq.read_schema(path)
actual = {
field.name: {key.decode(): value.decode() for key, value in field.metadata.items()}
for field in schema
if field.metadata
}
assert actual == expected
assert source.info.column_metadata == {"distance": {"unit": "cm"}, "label": {"source": "manual"}}
assert list(source) == rowsWindows/Python 3.12.14/PyArrow 25.0.1; Ruff check/format applied. The first full-module run hit Windows path-length errors in three existing cache round-trip tests; rerunning with a short basetemp passed all 31 (one existing PyArrow SortOptions deprecation warning). No live Hub, distributed-worker, or full-suite claim. AI disclosure: Codex designed and ran these checks under @JonnyFaeth's standing authorization; Jonathan has not personally reviewed this run. |
|
Thanks for the additional verification and for the test suggestion! Added Verified locally: all 31 tests in |
Summary
Follow-up to #9064 (
Dataset.with_column_metadata): brings column-level Arrow field metadata support to streaming datasets (IterableDatasetandIterableDatasetDict) and preservescolumn_metadataacross streaming transforms, conversions, and Parquet exports.Changes
IterableDataset.with_column_metadata()andIterableDatasetDict.with_column_metadata(), matching the validation and immutability behavior ofDataset.with_column_metadata()while also supportingIterableDatasetinstances whosefeaturesare unknown (None).IterableDatasetcolumn operations (rename_column,rename_columns,remove_columns,select_columns, andmap(remove_columns=...)) to rename or pruneDatasetInfo.column_metadataaccordingly.column_metadatainDataset.to_iterable_dataset().IterableDataset.to_parquet()and multi-shardIterableDataset._write_parquet_shards()(used bypush_to_hub).docs/source/package_reference/main_classes.mdx.tests/test_column_metadata.pycovering validation, streaming transforms,concatenate_datasets/interleave_datasets, Parquet round-tripping, multi-shard exports, andIterableDatasetDict.Verification
pytest -v tests/test_column_metadata.py— 23 passedpytest -q tests/test_iterable_dataset.py -k "rename_column or remove_columns or select_columns or to_parquet" -m "not integration"— 32 passedruff checkandruff format --checkon all modified files — 0 issues