# IndexError: list index out of range while processing shard 4 of dataset 'my_dataset'

- **ID:** `huggingface/dataset-sharding-index-out-of-range`
- **Domain:** huggingface
- **Category:** data_error
- **Verification:** ai_generated
- **Fix Rate:** 88%

## Root Cause

Dataset shard file is corrupted or incomplete, causing fewer examples than expected when splitting into shards.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| huggingface/datasets 2.18.0 | active | — | — |
| huggingface/datasets 2.19.0 | active | — | — |
| huggingface/datasets 2.20.0 | active | — | — |

## Workarounds

1. **Clear the dataset cache and re-download: `import datasets; datasets.load_dataset('my_dataset', cache_dir='/tmp/fresh_cache')`** (85% success)
   ```
   Clear the dataset cache and re-download: `import datasets; datasets.load_dataset('my_dataset', cache_dir='/tmp/fresh_cache')`
   ```
2. **Manually verify shard files: `ls ~/.cache/huggingface/datasets/my_dataset/*.arrow` and remove any zero-byte files before re-loading.** (80% success)
   ```
   Manually verify shard files: `ls ~/.cache/huggingface/datasets/my_dataset/*.arrow` and remove any zero-byte files before re-loading.
   ```

## Dead Ends

- **Increase shard count to reduce per-shard size** — The error is due to a corrupted shard file, not shard size. Changing shard count doesn't fix the underlying data corruption. (75% fail)
- **Re-download the entire dataset without checking shard integrity** — If the cache is corrupt, simply re-downloading without clearing the cache may reuse the same corrupted file. (60% fail)
