Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

docs: Add column overwrite example to batch mapping guide #7737

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Sanjaykumar030 wants to merge 2 commits into huggingface:main
base: main
Choose a base branch
Loading
from Sanjaykumar030:main

Conversation

Copy link

@Sanjaykumar030 Sanjaykumar030 commented Aug 13, 2025

This PR adds a complementary example showing the column-overwriting pattern, which is both more direct and more flexible for many transformations.

Proposed Change

The original remove_columns example remains untouched. Below it, this PR introduces an alternative approach that overwrites an existing column during batch mapping.

This teaches users a core .map() capability for in-place transformations without extra intermediate steps.

New Example:

>>> from datasets import Dataset
>>> dataset = Dataset.from_dict({"a": [0, 1, 2]})
# Overwrite "a" directly to duplicate each value
>>> duplicated_dataset = dataset.map(
... lambda batch: {"a": [x for x in batch["a"] for _ in range(2)]},
... batched=True
... )
>>> duplicated_dataset
Dataset({
 features: ['a'],
 num_rows: 6
})
>>> duplicated_dataset["a"]
[0, 0, 1, 1, 2, 2]

Copy link
Author

Hi @lhoestq, just a gentle follow-up on this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

1 participant

AltStyle によって変換されたページ (->オリジナル) /