Skip to content

Allow to_iterable_dataset() on a dataset with no rows - #8388

Open
LeSingh1 wants to merge 1 commit into
huggingface:mainfrom
LeSingh1:fix/to-iterable-dataset-empty
Open

Allow to_iterable_dataset() on a dataset with no rows#8388
LeSingh1 wants to merge 1 commit into
huggingface:mainfrom
LeSingh1:fix/to-iterable-dataset-empty

Conversation

@LeSingh1

@LeSingh1 LeSingh1 commented Aug 4, 2026

Copy link
Copy Markdown

Dataset.to_iterable_dataset() defaults to num_shards=1, but the guard rejects any num_shards > len(self), so it always raises on an empty dataset:

>>> Dataset.from_dict({"a": []}).to_iterable_dataset()
ValueError: Unable to shard a dataset of size 0 into 1 shards (the number of shards exceeds the number of samples).

A dataset with no rows still has one (empty) shard, and the num_shards == 1 branch below never calls .shard(), so no other change was needed. Requesting more than one shard from an empty dataset still raises as before.

This matches the empty-dataset exemption proposed for Dataset.shard in #8190, and is the same family as #8385 (save_to_disk on a dataset with no rows).

Added test_dataset_to_iterable_dataset_empty; it fails on main with the ValueError above and passes with the change. tests/test_arrow_dataset.py → 400 passed, 25 skipped.

`Dataset.to_iterable_dataset()` defaults to `num_shards=1`, but the guard
rejected any `num_shards > len(self)`, so it always raised on an empty
dataset:

    ValueError: Unable to shard a dataset of size 0 into 1 shards
    (the number of shards exceeds the number of samples).

A dataset with no rows still has one (empty) shard, and the `num_shards == 1`
branch below does not call `.shard()` at all, so nothing else had to change.
Requesting more than one shard from an empty dataset still raises.
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