Skip to content

Preserve features after IterableDataset.add_column - #8379

Open
kiwigitops wants to merge 1 commit into
huggingface:mainfrom
kiwigitops:fix-iterable-add-column-features
Open

Preserve features after IterableDataset.add_column#8379
kiwigitops wants to merge 1 commit into
huggingface:mainfrom
kiwigitops:fix-iterable-add-column-features

Conversation

@kiwigitops

Copy link
Copy Markdown

Summary

  • preserve known IterableDataset features when add_column appends a streaming column
  • infer the appended column feature from the provided column values
  • add a regression test for add_column after resolving iterable dataset features

Fixes #5752.

Testing

  • local repro with IterableDataset.from_generator(...).add_column(...)
  • python -m pytest tests/test_iterable_dataset.py::test_iterable_dataset_add_column tests/test_iterable_dataset.py::test_iterable_dataset_add_column_preserves_features
  • python -m pytest tests/test_iterable_dataset.py::test_pickle_after_many_transforms

return self.map(partial(add_column_fn, name=name, column=column), with_indices=True)
features = self.features.copy() if self.features is not None else None
if features is not None:
features.update(_infer_features_from_batch({name: column}))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inferring off {name: column} builds an arrow table from the whole column, which both copies the full column up front and narrows what add_column accepts: the signature allows np.array, and pa.Table.from_pydict raises ArrowInvalid: only handle 1-dimensional arrays for a 2D ndarray, so a call that used to just end up untyped now blows up before map. inferring from column[:1] (and falling back to None on ArrowInvalid) would keep that working. also worth mirroring Dataset.add_column's feature= arg so the caller can skip inference entirely.

return self.map(partial(add_column_fn, name=name, column=column), with_indices=True)
features = self.features.copy() if self.features is not None else None
if features is not None:
features.update(_infer_features_from_batch({name: column}))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the docstring types column as Union[list, np.array], and a 2-D ndarray (adding an embedding column) goes straight into pa.Table.from_pydict here and raises ArrowInvalid: only handle 1-dimensional arrays. that used to work since features stayed None. worth wrapping the infer in a try and falling back to features=None, or converting to a list of rows first.

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.

Streaming dataset looses .feature method after .add_column

2 participants