Regression: from_generator crashes if one generator call returns no results

### Describe the bug

Dataset.from_generator splits any list kwarg to the generator and makes a separate call to the generator for each member of the list even in the num_proc=1 case.
I have a generator that processes a number of files, filtering them and producing examples. It used to be the case that things worked fine if one of the files produced no examples.
It doesn't work any more.
I believe that commit 2ed6f72d88c0f37b75751cd0cd41a485439e16c9 is responsible.
What ends up happening is that the code tries to update input shard lengths but the list of shard lengths is still empty.

### Steps to reproduce the bug

```python
import datasets


def gen_examples(num_examples, fingerprint):
    assert len(num_examples) == 1
    for x in range(num_examples[0]):
        yield dict(feature=x)
        

ds = datasets.Dataset.from_generator(gen_examples, gen_kwargs=dict(num_examples=[0,1],
                                                                    fingerprint=str(id([]))))
```

Traceback looks like
```

Generating train split: 0 examples [00:00, ? examples/s]
Generating train split: 0 examples [00:00, ? examples/s]
Traceback (most recent call last):
  File "/usr/local/lib/python3.13/dist-packages/datasets/builder.py", line 1598, in _prepare_split_single
    original_shard_lengths[original_shard_id] += 1
    ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
IndexError: list index out of range

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/srv/models/zendegi_ai/sexpositive-sft/ai-tools/training_tools/foo.py", line 10, in <module>
    ds = datasets.Dataset.from_generator(gen_examples, gen_kwargs=dict(num_examples=[0,1],
                                                                        fingerprint=str(id([]))))
  File "/usr/local/lib/python3.13/dist-packages/datasets/arrow_dataset.py", line 1204, in from_generator
    ).read()
      ~~~~^^
  File "/usr/local/lib/python3.13/dist-packages/datasets/io/generator.py", line 52, in read
    self.builder.download_and_prepare(
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        download_config=download_config,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<3 lines>...
        num_proc=self.num_proc,
        ^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/local/lib/python3.13/dist-packages/datasets/builder.py", line 884, in download_and_prepare
    self._download_and_prepare(
    ~~~~~~~~~~~~~~~~~~~~~~~~~~^
        dl_manager=dl_manager,
        ^^^^^^^^^^^^^^^^^^^^^^
    ...<2 lines>...
        **download_and_prepare_kwargs,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/local/lib/python3.13/dist-packages/datasets/builder.py", line 1634, in _download_and_prepare
    super()._download_and_prepare(
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        dl_manager,
        ^^^^^^^^^^^
        verification_mode,
        ^^^^^^^^^^^^^^^^^^
        **prepare_splits_kwargs,
        ^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/local/lib/python3.13/dist-packages/datasets/builder.py", line 947, in _download_and_prepare
    self._prepare_split(split_generator, **prepare_split_kwargs)
    ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/dist-packages/datasets/builder.py", line 1438, in _prepare_split
    for job_id, done, content in self._prepare_split_single(
                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~^
        gen_kwargs=gen_kwargs, job_id=job_id, **_prepare_split_args
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ):
    ^
  File "/usr/local/lib/python3.13/dist-packages/datasets/builder.py", line 1617, in _prepare_split_single
    raise DatasetGenerationError("An error occurred while generating the dataset") from e
datasets.exceptions.DatasetGenerationError: An error occurred while generating the dataset
```

### Expected behavior

I expect a dataset with one example.
In my case it's fairly easy to work around this. Ideally this behavior would be supported.
If it's not going to be supported, catching the situation and returning a "generators must always return at least one example" error would have saved me hours of debugging.


### Environment info


Copy-and-paste the text below in your GitHub issue.

- `datasets` version: 4.5.0
- Platform: Linux-6.18.5+deb14-amd64-x86_64-with-glibc2.41
- Python version: 3.13.5
- `huggingface_hub` version: 1.4.1
- PyArrow version: 23.0.0
- Pandas version: 3.0.0
- `fsspec` version: 2025.10.0



Comments: