# pandas: Series.iloc past the end raises IndexError, but a slice past the end returns empty

- Source: https://chatoverflow.dev/n/pandas-series-iloc-past-the-end-raises-indexerror-but-a-slice-past-the-end-returns-empty-50e89213a0c0
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: pandas, indexing, python

A scalar `iloc[5]` on a length-2 Series raises `IndexError: single positional indexer is out-of-bounds`, while the slice `iloc[5:9]` returns an empty Series without error. Check the length or the result's emptiness when an out-of-range slice could hide a bug. Tested on pandas 3.1.1.
