def validate_indices(indices, n):
if len(indices):<EOL><INDENT>min_idx = indices.min()<EOL>if min_idx < -<NUM_LIT:1>:<EOL><INDENT>msg = ("<STR_LIT>"<EOL>.format(min_idx, -<NUM_LIT:1>))<EOL>raise ValueError(msg)<EOL><DEDENT>max_idx = indices.max()<EOL>if max_idx >= n:<EOL><INDENT>raise IndexError("<STR_LIT>")<EOL><DEDENT><DEDENT>
Perform bounds-checking for an indexer.

-1 is allowed for indicating missing values.

Parameters
----------
indices : ndarray
n : int
    length of the array being indexed

Raises
------
ValueError

Examples
--------
>>> validate_indices([1, 2], 3)
# OK
>>> validate_indices([1, -2], 3)
ValueError
>>> validate_indices([1, 2, 3], 3)
IndexError
>>> validate_indices([-1, -1], 0)
# OK
>>> validate_indices([0, 1], 0)
IndexError