Repository: pandas-dev/pandas

Issue:
.ix[int_number] falls back to positional indexing with MultiIndex with integers on first level
#### Code Sample, a copy-pastable example if possible

```python
In [2]: pd.Series(range(10), index=range(10, 20)).ix[5]
[...]
KeyError: 5

In [3]: pd.Series(range(10), index=pd.MultiIndex.from_product([range(10, 20), [1]])).loc[5]
[...]
KeyError: 'the label [5] is not in the [index]'

In [4]: pd.Series(range(10), index=pd.MultiIndex.from_product([range(10, 20), [1]])).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[4]: 5
```

#### Problem description

Yeah, I know, who cares about ``.ix`` anyway... it's just that this came out while refactoring, it is mistakenly tested, and I will push a fix, so this is to document the change in behaviour.

#### Expected Output

``KeyError`` also in ``Out[4]:``

#### Output of ``pd.show_versions()``

<details>

INSTALLED VERSIONS
------------------
commit: f1ffc5fae06a7294dc831887b0d76177aec9b708
python: 3.5.3.final.0
python-bits: 64
OS: Linux
OS-release: 4.9.0-6-amd64
machine: x86_64
processor: 
byteorder: little
LC_ALL: None
LANG: it_IT.UTF-8
LOCALE: it_IT.UTF-8

pandas: 0.24.0.dev0+141.gf1ffc5fae
pytest: 3.5.0
pip: 9.0.1
setuptools: 39.2.0
Cython: 0.25.2
numpy: 1.14.3
scipy: 0.19.0
pyarrow: None
xarray: None
IPython: 6.2.1
sphinx: 1.5.6
patsy: 0.5.0
dateutil: 2.7.3
pytz: 2018.4
blosc: None
bottleneck: 1.2.0dev
tables: 3.3.0
numexpr: 2.6.1
feather: 0.3.1
matplotlib: 2.2.2.post1153+gff6786446
openpyxl: 2.3.0
xlrd: 1.0.0
xlwt: 1.3.0
xlsxwriter: 0.9.6
lxml: 4.1.1
bs4: 4.5.3
html5lib: 0.999999999
sqlalchemy: 1.0.15
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: 0.2.1


</details>



Discussion:

Resolving patch:
diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py
--- a/pandas/core/indexing.py
+++ b/pandas/core/indexing.py
@@ -13,7 +13,6 @@
     is_iterator,
     is_scalar,
     is_sparse,
-    _is_unorderable_exception,
     _ensure_platform_int)
 from pandas.core.dtypes.missing import isna, _infer_fill_value
 from pandas.errors import AbstractMethodError
@@ -139,10 +138,7 @@ def _get_label(self, label, axis=None):
             # as its basically direct indexing
             # but will fail when the index is not present
             # see GH5667
-            try:
-                return self.obj._xs(label, axis=axis)
-            except:
-                return self.obj[label]
+            return self.obj._xs(label, axis=axis)
         elif isinstance(label, tuple) and isinstance(label[axis], slice):
             raise IndexingError('no slices here, handle elsewhere')
 
@@ -1797,9 +1793,8 @@ class _LocIndexer(_LocationIndexer):
 
     @Appender(_NDFrameIndexer._validate_key.__doc__)
     def _validate_key(self, key, axis):
-        ax = self.obj._get_axis(axis)
 
-        # valid for a label where all labels are in the index
+        # valid for a collection of labels (we check their presence later)
         # slice of labels (where start-end in labels)
         # slice of integers (only if in the labels)
         # boolean
@@ -1807,32 +1802,11 @@ def _validate_key(self, key, axis):
         if isinstance(key, slice):
             return
 
-        elif com.is_bool_indexer(key):
+        if com.is_bool_indexer(key):
             return
 
-        elif not is_list_like_indexer(key):
-
-            def error():
-                if isna(key):
-                    raise TypeError("cannot use label indexing with a null "
-                                    "key")
-                raise KeyError(u"the label [{key}] is not in the [{axis}]"
-                               .format(key=key,
-                                       axis=self.obj._get_axis_name(axis)))
-
-            try:
-                key = self._convert_scalar_indexer(key, axis)
-            except TypeError as e:
-
-                # python 3 type errors should be raised
-                if _is_unorderable_exception(e):
-                    error()
-                raise
-            except:
-                error()
-
-            if not ax.contains(key):
-                error()
+        if not is_list_like_indexer(key):
+            self._convert_scalar_indexer(key, axis)
 
     def _is_scalar_access(self, key):
         # this is a shortcut accessor to both .loc and .iloc


Test patch:
diff --git a/pandas/tests/indexes/datetimes/test_partial_slicing.py b/pandas/tests/indexes/datetimes/test_partial_slicing.py
--- a/pandas/tests/indexes/datetimes/test_partial_slicing.py
+++ b/pandas/tests/indexes/datetimes/test_partial_slicing.py
@@ -11,6 +11,8 @@
                     date_range, Index, Timedelta, Timestamp)
 from pandas.util import testing as tm
 
+from pandas.core.indexing import IndexingError
+
 
 class TestSlicing(object):
     def test_dti_slicing(self):
@@ -313,12 +315,12 @@ def test_partial_slicing_with_multiindex(self):
         result = df_multi.loc[('2013-06-19 09:30:00', 'ACCT1', 'ABC')]
         tm.assert_series_equal(result, expected)
 
-        # this is a KeyError as we don't do partial string selection on
-        # multi-levels
+        # this is an IndexingError as we don't do partial string selection on
+        # multi-levels.
         def f():
             df_multi.loc[('2013-06-19', 'ACCT1', 'ABC')]
 
-        pytest.raises(KeyError, f)
+        pytest.raises(IndexingError, f)
 
         # GH 4294
         # partial slice on a series mi
diff --git a/pandas/tests/indexing/test_multiindex.py b/pandas/tests/indexing/test_multiindex.py
--- a/pandas/tests/indexing/test_multiindex.py
+++ b/pandas/tests/indexing/test_multiindex.py
@@ -230,7 +230,8 @@ def test_iloc_getitem_multiindex(self):
         # corner column
         rs = mi_int.iloc[2, 2]
         with catch_warnings(record=True):
-            xp = mi_int.ix[:, 2].ix[2]
+            # First level is int - so use .loc rather than .ix (GH 21593)
+            xp = mi_int.loc[(8, 12), (4, 10)]
         assert rs == xp
 
         # this is basically regular indexing
@@ -278,6 +279,12 @@ def test_loc_multiindex(self):
             xp = mi_int.ix[4]
         tm.assert_frame_equal(rs, xp)
 
+        # missing label
+        pytest.raises(KeyError, lambda: mi_int.loc[2])
+        with catch_warnings(record=True):
+            # GH 21593
+            pytest.raises(KeyError, lambda: mi_int.ix[2])
+
     def test_getitem_partial_int(self):
         # GH 12416
         # with single item