def sanitize_index(data, index, copy=False):
if index is None:<EOL><INDENT>return data<EOL><DEDENT>if len(data) != len(index):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if isinstance(data, ABCIndexClass) and not copy:<EOL><INDENT>pass<EOL><DEDENT>elif isinstance(data, (ABCPeriodIndex, ABCDatetimeIndex)):<EOL><INDENT>data = data._values<EOL>if copy:<EOL><INDENT>data = data.copy()<EOL><DEDENT><DEDENT>elif isinstance(data, np.ndarray):<EOL><INDENT>if data.dtype.kind in ['<STR_LIT:M>', '<STR_LIT:m>']:<EOL><INDENT>data = sanitize_array(data, index, copy=copy)<EOL><DEDENT><DEDENT>return data<EOL>
Sanitize an index type to return an ndarray of the underlying, pass
through a non-Index.