Skip to content

feat(map): reuse unchanged columns when input_columns specified to reduce disk usage (#6013) #7626

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
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ArjunJagdale
Copy link
Contributor

Summary

This PR addresses #6013 by reusing unchanged columns from the original dataset in the map() method when input_columns is specified.

What’s Implemented

  • Injected logic at the end of Dataset.map() to:
    • Identify untouched columns not in input_columns or remove_columns
    • Select those columns from the original dataset
    • Concatenate them with the transformed result using pyarrow.concat_tables

Example Behavior

ds = Dataset.from_dict({"a": [1, 2], "b": [3, 4]})
ds2 = ds.map(lambda x: {"c": x["a"] + 10}, input_columns=["a"], remove_columns=["a"])
print(ds2.column_names)  # Output: ['b', 'c']

Column b is reused from the original dataset.

Notes

  • This keeps disk usage and caching minimal by avoiding full dataset duplication.
  • Only triggered when input_columns is set.

cc @lhoestq @mariosasko for review 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant