# Buggy code
def _getitem_axis(self, key, axis=None):
    if axis is None:
        axis = self.axis or 0

    labels = self.obj._get_axis(axis)
    key = self._get_partial_string_timestamp_match_key(key, labels)

    if isinstance(key, slice):
        self._has_valid_type(key, axis)
        return self._get_slice_axis(key, axis=axis)
    elif com.is_bool_indexer(key):
        return self._getbool_axis(key, axis=axis)
    elif is_list_like_indexer(key):
        # convert various list-like indexers
        # to a list of keys
        # we will use the *values* of the object
        # and NOT the index if its a PandasObject
        if isinstance(labels, MultiIndex):
            if isinstance(key, (ABCSeries, np.ndarray)) and key.ndim <= 1:
                # Series, or 0,1 ndim ndarray
                # GH 14730
                key = list(key)
            elif isinstance(key, ABCDataFrame):
                # GH 15438
                raise NotImplementedError(
                    "Indexing a MultiIndex with a DataFrame key is not implemented"
                )
            elif hasattr(key, "ndim") and key.ndim > 1:
                raise NotImplementedError(
                    "Indexing a MultiIndex with a "
                    "multidimensional key is not "
                    "implemented"
                )

            if (
                not isinstance(key, tuple)
                and len(key) > 1
                and not isinstance(key[0], tuple)
            ):
                key = tuple([key])

        # an iterable multi-selection
        if not (isinstance(key, tuple) and isinstance(labels, MultiIndex)):
            if hasattr(key, "ndim") and key.ndim > 1:
                raise ValueError("Cannot index with multidimensional key")

            return self._getitem_iterable(key, axis=axis)

        # nested tuple slicing
        if is_nested_tuple(key, labels):
            locs = labels.get_locs(key)
            indexer = [slice(None)] * self.ndim
            indexer[axis] = locs
            return self.obj.iloc[tuple(indexer)]

    # fall thru to straight lookup
    self._has_valid_type(key, axis)
    return self._get_label(key, axis=axis)


# Traceback (KeyError)
In [2]: pd.Series(range(3)).ix[5]
/usr/bin/ipython3:1: DeprecationWarning:
.ix is deprecated. Please use
.loc for label based indexing or
.iloc for positional indexing

See the documentation here:
http://pandas.pydata.org/pandas-docs/stable/indexing.html#ix-indexer-is-deprecated
#! /bin/sh
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
/home/nobackup/repo/pandas/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
3017             try:
-> 3018                 return self._engine.get_loc(key)
3019             except KeyError:

/home/nobackup/repo/pandas/pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc (pandas/_libs/index.c:5729)()
138
--> 139     cpdef get_loc(self, object val):
140         if is_definitely_invalid_key(val):

/home/nobackup/repo/pandas/pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc (pandas/_libs/index.c:5575)()
160         try:
--> 161             return self.mapping.get_item(val)
162         except (TypeError, ValueError):

/home/nobackup/repo/pandas/pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item (pandas/_libs/hashtable.c:15398)()
957
--> 958     cpdef get_item(self, int64_t val):
959         cdef khiter_t k

/home/nobackup/repo/pandas/pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item (pandas/_libs/hashtable.c:15342)()
963         else:
--> 964             raise KeyError(val)
965

KeyError: 5

During handling of the above exception, another exception occurred:

KeyError                                  Traceback (most recent call last)
/home/nobackup/repo/pandas/pandas/core/indexing.py in _get_label(self, label, axis)
131             try:
--> 132                 return self.obj._xs(label, axis=axis)
133             except:

/home/nobackup/repo/pandas/pandas/core/generic.py in xs(self, key, axis, level, drop_level)
2991         else:
-> 2992             loc = self.index.get_loc(key)
2993

/home/nobackup/repo/pandas/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
3019             except KeyError:
-> 3020                 return self._engine.get_loc(self._maybe_cast_indexer(key))
3021

/home/nobackup/repo/pandas/pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc (pandas/_libs/index.c:5729)()
138
--> 139     cpdef get_loc(self, object val):
140         if is_definitely_invalid_key(val):

/home/nobackup/repo/pandas/pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc (pandas/_libs/index.c:5575)()
160         try:
--> 161             return self.mapping.get_item(val)
162         except (TypeError, ValueError):

/home/nobackup/repo/pandas/pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item (pandas/_libs/hashtable.c:15398)()
957
--> 958     cpdef get_item(self, int64_t val):
959         cdef khiter_t k

/home/nobackup/repo/pandas/pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item (pandas/_libs/hashtable.c:15342)()
963         else:
--> 964             raise KeyError(val)
965

KeyError: 5

During handling of the above exception, another exception occurred:

KeyError                                  Traceback (most recent call last)
<ipython-input-2-bba00cd402c6> in <module>()
----> 1 pd.Series(range(3)).ix[5]

/home/nobackup/repo/pandas/pandas/core/indexing.py in __getitem__(self, key)
118
119             key = com._apply_if_callable(key, self.obj)
--> 120             return self._getitem_axis(key, axis=axis)
121
122     def _get_label(self, label, axis=None):

/home/nobackup/repo/pandas/pandas/core/indexing.py in _getitem_axis(self, key, axis)
1104                     return self._get_loc(key, axis=axis)
1105
-> 1106             return self._get_label(key, axis=axis)
1107
1108     def _getitem_iterable(self, key, axis=None):

/home/nobackup/repo/pandas/pandas/core/indexing.py in _get_label(self, label, axis)
132                 return self.obj._xs(label, axis=axis)
133             except:
--> 134                 return self.obj[label]
135         elif isinstance(label, tuple) and isinstance(label[axis], slice):
136             raise IndexingError('no slices here, handle elsewhere')

/home/nobackup/repo/pandas/pandas/core/series.py in __getitem__(self, key)
753         key = com._apply_if_callable(key, self)
754         try:
--> 755             result = self.index.get_value(self, key)
756
757             if not is_scalar(result):

/home/nobackup/repo/pandas/pandas/core/indexes/base.py in get_value(self, series, key)
3051         try:
3052             return self._engine.get_value(s, k,
-> 3053                                           tz=getattr(series.dtype, 'tz', None))
3054         except KeyError as e1:
3055             if len(self) > 0 and self.inferred_type in ['integer', 'boolean']:

/home/nobackup/repo/pandas/pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_value (pandas/_libs/index.c:4856)()
103         return val in self.mapping
104
--> 105     cpdef get_value(self, ndarray arr, object key, object tz=None):
106         """
107         arr : 1-dimensional ndarray

/home/nobackup/repo/pandas/pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_value (pandas/_libs/index.c:4539)()
111             void* data_ptr
112
--> 113         loc = self.get_loc(key)
114         if PySlice_Check(loc) or cnp.PyArray_Check(loc):
115             return arr[loc]

/home/nobackup/repo/pandas/pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc (pandas/_libs/index.c:5575)()
159
160         try:
--> 161             return self.mapping.get_item(val)
162         except (TypeError, ValueError):
163             raise KeyError(val)

/home/nobackup/repo/pandas/pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item (pandas/_libs/hashtable.c:15398)()
956                                        sizeof(uint32_t)) # flags
957
--> 958     cpdef get_item(self, int64_t val):
959         cdef khiter_t k
960         k = kh_get_int64(self.table, val)

/home/nobackup/repo/pandas/pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item (pandas/_libs/hashtable.c:15342)()
962             return self.table.vals[k]
963         else:
--> 964             raise KeyError(val)
965
966     cpdef set_item(self, int64_t key, Py_ssize_t val):

KeyError: 5

In [3]: pd.Series(range(3)).ix[[5]]
/usr/bin/ipython3:1: DeprecationWarning:
.ix is deprecated. Please use
.loc for label based indexing or
.iloc for positional indexing

See the documentation here:
http://pandas.pydata.org/pandas-docs/stable/indexing.html#ix-indexer-is-deprecated
#! /bin/sh
Out[3]:
5   NaN
dtype: float64

# Fixed code
def _getitem_axis(self, key, axis=None):
    if axis is None:
        axis = self.axis or 0

    if is_iterator(key):
        key = list(key)

    labels = self.obj._get_axis(axis)
    key = self._get_partial_string_timestamp_match_key(key, labels)

    if isinstance(key, slice):
        self._validate_key(key, axis)
        return self._get_slice_axis(key, axis=axis)
    elif com.is_bool_indexer(key):
        return self._getbool_axis(key, axis=axis)
    elif is_list_like_indexer(key):
        # convert various list-like indexers
        # to a list of keys
        # we will use the *values* of the object
        # and NOT the index if its a PandasObject
        if isinstance(labels, MultiIndex):
            if isinstance(key, (ABCSeries, np.ndarray)) and key.ndim <= 1:
                # Series, or 0,1 ndim ndarray
                # GH 14730
                key = list(key)
            elif isinstance(key, ABCDataFrame):
                # GH 15438
                raise NotImplementedError(
                    "Indexing a MultiIndex with a DataFrame key is not implemented"
                )
            elif hasattr(key, "ndim") and key.ndim > 1:
                raise NotImplementedError(
                    "Indexing a MultiIndex with a "
                    "multidimensional key is not "
                    "implemented"
                )

            if (
                not isinstance(key, tuple)
                and len(key) > 1
                and not isinstance(key[0], tuple)
            ):
                key = tuple([key])

        # an iterable multi-selection
        if not (isinstance(key, tuple) and isinstance(labels, MultiIndex)):
            if hasattr(key, "ndim") and key.ndim > 1:
                raise ValueError("Cannot index with multidimensional key")

            return self._getitem_iterable(key, axis=axis)

        # nested tuple slicing
        if is_nested_tuple(key, labels):
            locs = labels.get_locs(key)
            indexer = [slice(None)] * self.ndim
            indexer[axis] = locs
            return self.obj.iloc[tuple(indexer)]

    # fall thru to straight lookup
    self._validate_key(key, axis)
    return self._get_label(key, axis=axis)