From 8d644de23f00aaa96ad74dfd63128caa664e2b25 Mon Sep 17 00:00:00 2001 From: Vineeth Sai Date: Fri, 4 Sep 2026 09:34:09 -0700 Subject: [PATCH 1/2] Print the repr these feature examples actually produce Image, Pdf, Nifti and Video all declare `id` with repr=False, so none of them can print the `X(decode=True, id=None)` their examples show. Image also has a `mode` field the example omits, and Video has five more fields that do print. Also close the string literal in Video's last example, which made the line unparseable, and add the `>>> ds[0]["image"]` line Image's last block needs to produce the dict under it, the way pdf.py and nifti.py already do. --- src/datasets/features/image.py | 3 ++- src/datasets/features/nifti.py | 2 +- src/datasets/features/pdf.py | 2 +- src/datasets/features/video.py | 4 ++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/datasets/features/image.py b/src/datasets/features/image.py index 9a7953dd6bc..4f64510aae2 100644 --- a/src/datasets/features/image.py +++ b/src/datasets/features/image.py @@ -75,10 +75,11 @@ class Image: >>> from datasets import load_dataset, Image >>> ds = load_dataset("AI-Lab-Makerere/beans", split="train") >>> ds.features["image"] - Image(decode=True, id=None) + Image(mode=None, decode=True) >>> ds[0]["image"] >>> ds = ds.cast_column('image', Image(decode=False)) + >>> ds[0]["image"] {'bytes': None, 'path': '/root/.cache/huggingface/datasets/downloads/extracted/b0a21163f78769a2cf11f58dfc767fb458fc7cea5c05dccc0144a2c0f0bc1292/train/healthy/healthy_train.85.jpg'} ``` diff --git a/src/datasets/features/nifti.py b/src/datasets/features/nifti.py index 1e78cad9e28..ce77d763850 100644 --- a/src/datasets/features/nifti.py +++ b/src/datasets/features/nifti.py @@ -86,7 +86,7 @@ class Nifti: >>> from datasets import Dataset, Nifti >>> ds = Dataset.from_dict({"nifti": ["path/to/file.nii.gz"]}).cast_column("nifti", Nifti()) >>> ds.features["nifti"] - Nifti(decode=True, id=None) + Nifti(decode=True) >>> ds[0]["nifti"] >>> ds = ds.cast_column("nifti", Nifti(decode=False)) diff --git a/src/datasets/features/pdf.py b/src/datasets/features/pdf.py index 74c7560d5ff..aa7ca92ceeb 100644 --- a/src/datasets/features/pdf.py +++ b/src/datasets/features/pdf.py @@ -54,7 +54,7 @@ class Pdf: >>> from datasets import Dataset, Pdf >>> ds = Dataset.from_dict({"pdf": ["path/to/pdf/file.pdf"]}).cast_column("pdf", Pdf()) >>> ds.features["pdf"] - Pdf(decode=True, id=None) + Pdf(decode=True) >>> ds[0]["pdf"] >>> ds = ds.cast_column("pdf", Pdf(decode=False)) diff --git a/src/datasets/features/video.py b/src/datasets/features/video.py index 8522c2cb122..559cd35226d 100644 --- a/src/datasets/features/video.py +++ b/src/datasets/features/video.py @@ -70,7 +70,7 @@ class Video: >>> from datasets import Dataset, Video >>> ds = Dataset.from_dict({"video":["path/to/Screen Recording.mov"]}).cast_column("video", Video()) >>> ds.features["video"] - Video(decode=True, id=None) + Video(decode=True, stream_index=None, dimension_order='NCHW', num_ffmpeg_threads=1, device='cpu', seek_mode='exact') >>> ds[0]["video"] >>> video = ds[0]["video"] @@ -81,7 +81,7 @@ class Video: 0.4333], dtype=torch.float64) duration_seconds: tensor([0.0167, 0.0167, 0.0167, 0.0167, 0.0167, 0.0167, 0.0167, 0.0167, 0.0167, 0.0167], dtype=torch.float64) - >>> ds.cast_column('video', Video(decode=False))[0]["video] + >>> ds.cast_column('video', Video(decode=False))[0]["video"] {'bytes': None, 'path': 'path/to/Screen Recording.mov'} ``` From 101bb1aaccb2eb3ee47f6be8d8493525be7cf9b4 Mon Sep 17 00:00:00 2001 From: Vineeth Sai Date: Fri, 11 Sep 2026 13:00:06 -0700 Subject: [PATCH 2/2] Fix five more feature reprs and the reorder_fields_as example Same drift as the four classes already in this PR, in two files it did not reach. iterable_dataset.py prints Audio with mono=True, id=None. Audio has no mono field at all, so the line is not just stale, it cannot be constructed, and id carries repr=False. It also prints Image(mode=None, decode=False, id=None). features.py Features.flatten prints List(Value('int32'), id=None) twice, and List keeps id out of its repr as well. Features.reorder_fields_as is a different miss. Its example builds f1 and f2 from plain dicts, but its own comment says "here List is defined at the root level", it imports List without using it, and the documented output is {'root': List({'b': ..., 'a': ...})}. The List wrapper was dropped from the two constructor lines at some point and the output was never updated. Putting it back makes the example agree with its comment, its import and its output. Checked against main: Audio(sampling_rate=8000) -> Audio(sampling_rate=8000, decode=True, num_channels=None, stream_index=None) Image(mode=None, decode=False) -> Image(mode=None, decode=False) List(Value('int32')) -> List(Value('int32')) f1.reorder_fields_as(f2) -> {'root': List({'b': Value('string'), 'a': Value('string')})} and f1.reorder_fields_as(f2).type == f2.type still holds, so the closing assert in that example is unchanged. --- src/datasets/features/features.py | 8 ++++---- src/datasets/iterable_dataset.py | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/datasets/features/features.py b/src/datasets/features/features.py index 62f4742eb7a..9c36e82e9b3 100644 --- a/src/datasets/features/features.py +++ b/src/datasets/features/features.py @@ -2325,8 +2325,8 @@ def reorder_fields_as(self, other: "Features") -> "Features": >>> from datasets import Features, List, Value >>> # let's say we have two features with a different order of nested fields (for a and b for example) - >>> f1 = Features({"root": {"a": Value("string"), "b": Value("string")}}) - >>> f2 = Features({"root": {"b": Value("string"), "a": Value("string")}}) + >>> f1 = Features({"root": List({"a": Value("string"), "b": Value("string")})}) + >>> f2 = Features({"root": List({"b": Value("string"), "a": Value("string")})}) >>> assert f1.type != f2.type >>> # re-ordering keeps the base structure (here List is defined at the root level), but makes the fields order match >>> f1.reorder_fields_as(f2) @@ -2378,8 +2378,8 @@ def flatten(self, max_depth=16) -> "Features": >>> from datasets import load_dataset >>> ds = load_dataset("rajpurkar/squad", split="train") >>> ds.features.flatten() - {'answers.answer_start': List(Value('int32'), id=None), - 'answers.text': List(Value('string'), id=None), + {'answers.answer_start': List(Value('int32')), + 'answers.text': List(Value('string')), 'context': Value('string'), 'id': Value('string'), 'question': Value('string'), diff --git a/src/datasets/iterable_dataset.py b/src/datasets/iterable_dataset.py index 2f7f5684778..35c11973d6c 100644 --- a/src/datasets/iterable_dataset.py +++ b/src/datasets/iterable_dataset.py @@ -4264,7 +4264,7 @@ def cast_column(self, column: str, feature: FeatureType) -> "IterableDataset": >>> from datasets import load_dataset, Audio >>> ds = load_dataset("PolyAI/minds14", name="en-US", split="train", streaming=True) >>> ds.features - {'audio': Audio(sampling_rate=8000, mono=True, decode=True, id=None), + {'audio': Audio(sampling_rate=8000, decode=True, num_channels=None, stream_index=None), 'english_transcription': Value('string'), 'intent_class': ClassLabel(num_classes=14, names=['abroad', 'address', 'app_error', 'atm_limit', 'balance', 'business_loan', 'card_issues', 'cash_deposit', 'direct_debit', 'freeze', 'high_value_payment', 'joint_account', 'latest_transactions', 'pay_bill']), 'lang_id': ClassLabel(num_classes=14, names=['cs-CZ', 'de-DE', 'en-AU', 'en-GB', 'en-US', 'es-ES', 'fr-FR', 'it-IT', 'ko-KR', 'nl-NL', 'pl-PL', 'pt-PT', 'ru-RU', 'zh-CN']), @@ -4272,7 +4272,7 @@ def cast_column(self, column: str, feature: FeatureType) -> "IterableDataset": 'transcription': Value('string')} >>> ds = ds.cast_column("audio", Audio(sampling_rate=16000)) >>> ds.features - {'audio': Audio(sampling_rate=16000, mono=True, decode=True, id=None), + {'audio': Audio(sampling_rate=16000, decode=True, num_channels=None, stream_index=None), 'english_transcription': Value('string'), 'intent_class': ClassLabel(num_classes=14, names=['abroad', 'address', 'app_error', 'atm_limit', 'balance', 'business_loan', 'card_issues', 'cash_deposit', 'direct_debit', 'freeze', 'high_value_payment', 'joint_account', 'latest_transactions', 'pay_bill']), 'lang_id': ClassLabel(num_classes=14, names=['cs-CZ', 'de-DE', 'en-AU', 'en-GB', 'en-US', 'es-ES', 'fr-FR', 'it-IT', 'ko-KR', 'nl-NL', 'pl-PL', 'pt-PT', 'ru-RU', 'zh-CN']), @@ -4377,7 +4377,7 @@ def decode(self, enable: bool = True, num_threads: int = 0) -> "IterableDataset" 'text': 'A distant celestial object with an icy crust, displaying a light blue shade, covered with round pits and rugged terrains.'} >>> ds = ds.decode(False) >>> ds.features - {'image': Image(mode=None, decode=False, id=None), + {'image': Image(mode=None, decode=False), 'text': Value('string')} >>> next(iter(ds)) {