def ensure_index(index_like, copy=False):
if isinstance(index_like, Index):<EOL><INDENT>if copy:<EOL><INDENT>index_like = index_like.copy()<EOL><DEDENT>return index_like<EOL><DEDENT>if hasattr(index_like, '<STR_LIT:name>'):<EOL><INDENT>return Index(index_like, name=index_like.name, copy=copy)<EOL><DEDENT>if is_iterator(index_like):<EOL><INDENT>index_like = list(index_like)<EOL><DEDENT>if isinstance(index_like, list):<EOL><INDENT>if type(index_like) != list:<EOL><INDENT>index_like = list(index_like)<EOL><DEDENT>converted, all_arrays = lib.clean_index_list(index_like)<EOL>if len(converted) > <NUM_LIT:0> and all_arrays:<EOL><INDENT>from .multi import MultiIndex<EOL>return MultiIndex.from_arrays(converted)<EOL><DEDENT>else:<EOL><INDENT>index_like = converted<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if copy:<EOL><INDENT>from copy import copy<EOL>index_like = copy(index_like)<EOL><DEDENT><DEDENT>return Index(index_like)<EOL>
Ensure that we have an index from some index-like object.

Parameters
----------
index : sequence
    An Index or other sequence
copy : bool

Returns
-------
index : Index or MultiIndex

Examples
--------
>>> ensure_index(['a', 'b'])
Index(['a', 'b'], dtype='object')

>>> ensure_index([('a', 'a'),  ('b', 'c')])
Index([('a', 'a'), ('b', 'c')], dtype='object')

>>> ensure_index([['a', 'a'], ['b', 'c']])
MultiIndex(levels=[['a'], ['b', 'c']],
           codes=[[0, 0], [0, 1]])

See Also
--------
ensure_index_from_sequences