def maybe_convert_indices(indices, n):
if isinstance(indices, list):<EOL><INDENT>indices = np.array(indices)<EOL>if len(indices) == <NUM_LIT:0>:<EOL><INDENT>return np.empty(<NUM_LIT:0>, dtype=np.intp)<EOL><DEDENT><DEDENT>mask = indices < <NUM_LIT:0><EOL>if mask.any():<EOL><INDENT>indices = indices.copy()<EOL>indices[mask] += n<EOL><DEDENT>mask = (indices >= n) | (indices < <NUM_LIT:0>)<EOL>if mask.any():<EOL><INDENT>raise IndexError("<STR_LIT>")<EOL><DEDENT>return indices<EOL>
Attempt to convert indices into valid, positive indices.

If we have negative indices, translate to positive here.
If we have indices that are out-of-bounds, raise an IndexError.

Parameters
----------
indices : array-like
    The array of indices that we are to convert.
n : int
    The number of elements in the array that we are indexing.

Returns
-------
valid_indices : array-like
    An array-like of positive indices that correspond to the ones
    that were passed in initially to this function.

Raises
------
IndexError : one of the converted indices either exceeded the number
    of elements (specified by `n`) OR was still negative.