Fix: Prevent loss of info.features and column_names in IterableDatasetDict.map when features is None
CONTRIBUTOR
Hi!
I haven’t included a test for this change, as the fix is quite small and targeted.
Please let me know if you’d like a test for this case or if you’d prefer to handle it during review.
Thanks!
2025-06-30T09:31:34Z
https://github.com/huggingface/datasets/pull/7658#issuecomment-3018453459
https://api.github.com/repos/huggingface/datasets/issues/7658
IC_kwDODunzps6z6fHT
https://api.github.com/repos/huggingface/datasets/issues/comments/3018453459/reactions
2025-06-30T09:31:34Z
https://api.github.com/repos/huggingface/datasets/issues/comments/3018453459
https://avatars.githubusercontent.com/u/142811259?v=4
https://api.github.com/users/ArjunJagdale/events{/privacy}
https://api.github.com/users/ArjunJagdale/followers
https://api.github.com/users/ArjunJagdale/following{/other_user}
https://api.github.com/users/ArjunJagdale/gists{/gist_id}
https://github.com/ArjunJagdale
ArjunJagdale
U_kgDOCIMgew
https://api.github.com/users/ArjunJagdale/orgs
https://api.github.com/users/ArjunJagdale/received_events
https://api.github.com/users/ArjunJagdale/repos
https://api.github.com/users/ArjunJagdale/starred{/owner}{/repo}
https://api.github.com/users/ArjunJagdale/subscriptions
User
https://api.github.com/users/ArjunJagdale
public
MEMBER
we can't know in advance the `features` after map() (it transforms the data !), so you can reuse the `features` from `info.features`
2025-07-01T13:24:43Z
https://github.com/huggingface/datasets/pull/7658#issuecomment-3024012842
https://api.github.com/repos/huggingface/datasets/issues/7658
IC_kwDODunzps60PsYq
https://api.github.com/repos/huggingface/datasets/issues/comments/3024012842/reactions
2025-07-01T13:24:43Z
https://api.github.com/repos/huggingface/datasets/issues/comments/3024012842
https://avatars.githubusercontent.com/u/42851186?v=4
https://api.github.com/users/lhoestq/events{/privacy}
https://api.github.com/users/lhoestq/followers
https://api.github.com/users/lhoestq/following{/other_user}
https://api.github.com/users/lhoestq/gists{/gist_id}
https://github.com/lhoestq
lhoestq
MDQ6VXNlcjQyODUxMTg2
https://api.github.com/users/lhoestq/orgs
https://api.github.com/users/lhoestq/received_events
https://api.github.com/users/lhoestq/repos
https://api.github.com/users/lhoestq/starred{/owner}{/repo}
https://api.github.com/users/lhoestq/subscriptions
User
https://api.github.com/users/lhoestq
public
CONTRIBUTOR
I'll the patch as suggested — `info.features = features` or `self.info.features` — to ensure schema preservation while keeping the logic simple and explicit. WDYT?

2025-07-01T16:13:22Z
https://github.com/huggingface/datasets/pull/7658#issuecomment-3024677084
https://api.github.com/repos/huggingface/datasets/issues/7658
IC_kwDODunzps60SOjc
https://api.github.com/repos/huggingface/datasets/issues/comments/3024677084/reactions
2025-07-01T16:13:22Z
https://api.github.com/repos/huggingface/datasets/issues/comments/3024677084
https://avatars.githubusercontent.com/u/142811259?v=4
https://api.github.com/users/ArjunJagdale/events{/privacy}
https://api.github.com/users/ArjunJagdale/followers
https://api.github.com/users/ArjunJagdale/following{/other_user}
https://api.github.com/users/ArjunJagdale/gists{/gist_id}
https://github.com/ArjunJagdale
ArjunJagdale
U_kgDOCIMgew
https://api.github.com/users/ArjunJagdale/orgs
https://api.github.com/users/ArjunJagdale/received_events
https://api.github.com/users/ArjunJagdale/repos
https://api.github.com/users/ArjunJagdale/starred{/owner}{/repo}
https://api.github.com/users/ArjunJagdale/subscriptions
User
https://api.github.com/users/ArjunJagdale
public
MEMBER
info.features should be None in the general case, and replaced by the user's `features` if it's passed explicitly with `map(..., features=...)`

https://github.com/huggingface/datasets/issues/7568 is not an issue we can fix
2025-07-01T16:17:07Z
https://github.com/huggingface/datasets/pull/7658#issuecomment-3024704891
https://api.github.com/repos/huggingface/datasets/issues/7658
IC_kwDODunzps60SVV7
https://api.github.com/repos/huggingface/datasets/issues/comments/3024704891/reactions
2025-07-01T16:17:07Z
https://api.github.com/repos/huggingface/datasets/issues/comments/3024704891
https://avatars.githubusercontent.com/u/42851186?v=4
https://api.github.com/users/lhoestq/events{/privacy}
https://api.github.com/users/lhoestq/followers
https://api.github.com/users/lhoestq/following{/other_user}
https://api.github.com/users/lhoestq/gists{/gist_id}
https://github.com/lhoestq
lhoestq
MDQ6VXNlcjQyODUxMTg2
https://api.github.com/users/lhoestq/orgs
https://api.github.com/users/lhoestq/received_events
https://api.github.com/users/lhoestq/repos
https://api.github.com/users/lhoestq/starred{/owner}{/repo}
https://api.github.com/users/lhoestq/subscriptions
User
https://api.github.com/users/lhoestq
public
CONTRIBUTOR
> info.features should be None in the general case, and replaced by the user's `features` if it's passed explicitly with `map(..., features=...)`
> 
> #7568 is not an issue we can fix

Thanks for the clarification! Totally makes sense now — I understand that features=None is the expected behavior post-map() unless explicitly passed, and that preserving old schema by default could lead to incorrect assumptions.
Closing this one — appreciate the feedback as always
2025-07-01T16:26:05Z
https://github.com/huggingface/datasets/pull/7658#issuecomment-3024730752
https://api.github.com/repos/huggingface/datasets/issues/7658
IC_kwDODunzps60SbqA
https://api.github.com/repos/huggingface/datasets/issues/comments/3024730752/reactions
2025-07-01T16:26:05Z
https://api.github.com/repos/huggingface/datasets/issues/comments/3024730752
https://avatars.githubusercontent.com/u/142811259?v=4
https://api.github.com/users/ArjunJagdale/events{/privacy}
https://api.github.com/users/ArjunJagdale/followers
https://api.github.com/users/ArjunJagdale/following{/other_user}
https://api.github.com/users/ArjunJagdale/gists{/gist_id}
https://github.com/ArjunJagdale
ArjunJagdale
U_kgDOCIMgew
https://api.github.com/users/ArjunJagdale/orgs
https://api.github.com/users/ArjunJagdale/received_events
https://api.github.com/users/ArjunJagdale/repos
https://api.github.com/users/ArjunJagdale/starred{/owner}{/repo}
https://api.github.com/users/ArjunJagdale/subscriptions
User
https://api.github.com/users/ArjunJagdale
public
This PR fixes a bug where calling `IterableDatasetDict.map()` or `IterableDataset.map()` with the default `features=None` argument would overwrite the existing `info.features` attribute with `None`. This, in turn, caused the resulting dataset to lose its schema, breaking downstream usage of attributes like `column_names`.

Why
Previously, the code would always set `info.features = features`, even if `features` was `None`. When mapping with removal of columns or other transformations, this led to the destruction of the schema and caused failures in code that relied on the dataset schema being present.

How
We now update `info.features` only if `features` is not `None`. This preserves the original schema unless the user explicitly provides a new one.

Reference
Fixes #7568