Repository: pandas-dev/pandas

Issue:
Incorrect Message in KeyError with MultiIndex
#### Code Sample

```python
X = pd.DataFrame(dict(A=[1, 1, 1, 2, 2, 2], B=[1, 2, 3, 1, 2, 3], C=[1, 2, 3, 4, 5, 6], D=list("abcdef")))
X = X.set_index(["A", "B", "C"])
X.loc[(1, 1, 2), :] 
```
#### Problem description

This correctly throws a `KeyError` but the message is incorrect, instead of showing `"KeyError: (1, 1, 2)"` it shows `"KeyError: 42"`

#### Output of ``pd.show_versions()``

<details>
                                                                           
INSTALLED VERSIONS
------------------
commit: None
python: 3.6.4.final.0
python-bits: 64
OS: Linux
OS-release: 4.18.16-200.fc28.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_GB.UTF-8
LOCALE: en_GB.UTF-8

pandas: 0.24.2
pytest: None
pip: 19.1.1
setuptools: 41.0.1
Cython: None
numpy: 1.16.4
scipy: 0.19.1
pyarrow: 0.13.0
xarray: None
IPython: 7.1.1
sphinx: None
patsy: 0.5.1
dateutil: 2.8.0
pytz: 2019.1
blosc: None
bottleneck: None
tables: None
numexpr: 2.6.4
feather: 0.4.0
matplotlib: 2.1.1
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml.etree: 4.3.0
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: 2.7.4 (dt dec pq3 ext lo64)
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None


</details>



Discussion:
pls try this on master / 0.25.rc0
The download link on the pandas home page appears to be broken. It points to https://pypi.org/project/pandas/0.25.0/#files
https://github.com/pandas-dev/pandas/releases

this is a release candidate 
Thanks. I set-up a fresh conda environment and installed pandas 0.25.0.rc0 and it shows the same incorrect behaviour. 

Resolving patch:
diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py
--- a/pandas/core/indexes/multi.py
+++ b/pandas/core/indexes/multi.py
@@ -2810,7 +2810,10 @@ def partial_selection(key, indexer=None):
 
                 if len(key) == self.nlevels and self.is_unique:
                     # Complete key in unique index -> standard get_loc
-                    return (self._engine.get_loc(key), None)
+                    try:
+                        return (self._engine.get_loc(key), None)
+                    except KeyError as e:
+                        raise KeyError(key) from e
                 else:
                     return partial_selection(key)
             else:


Test patch:
diff --git a/pandas/tests/indexing/multiindex/test_getitem.py b/pandas/tests/indexing/multiindex/test_getitem.py
--- a/pandas/tests/indexing/multiindex/test_getitem.py
+++ b/pandas/tests/indexing/multiindex/test_getitem.py
@@ -83,9 +83,9 @@ def test_series_getitem_returns_scalar(
 @pytest.mark.parametrize(
     "indexer,expected_error,expected_error_msg",
     [
-        (lambda s: s.__getitem__((2000, 3, 4)), KeyError, r"^356$"),
-        (lambda s: s[(2000, 3, 4)], KeyError, r"^356$"),
-        (lambda s: s.loc[(2000, 3, 4)], KeyError, r"^356$"),
+        (lambda s: s.__getitem__((2000, 3, 4)), KeyError, r"^\(2000, 3, 4\)$"),
+        (lambda s: s[(2000, 3, 4)], KeyError, r"^\(2000, 3, 4\)$"),
+        (lambda s: s.loc[(2000, 3, 4)], KeyError, r"^\(2000, 3, 4\)$"),
         (lambda s: s.loc[(2000, 3, 4, 5)], IndexingError, "Too many indexers"),
         (lambda s: s.__getitem__(len(s)), IndexError, "index out of bounds"),
         (lambda s: s[len(s)], IndexError, "index out of bounds"),
diff --git a/pandas/tests/indexing/multiindex/test_loc.py b/pandas/tests/indexing/multiindex/test_loc.py
--- a/pandas/tests/indexing/multiindex/test_loc.py
+++ b/pandas/tests/indexing/multiindex/test_loc.py
@@ -389,7 +389,7 @@ def test_loc_getitem_lowerdim_corner(multiindex_dataframe_random_data):
     df = multiindex_dataframe_random_data
 
     # test setup - check key not in dataframe
-    with pytest.raises(KeyError, match=r"^11$"):
+    with pytest.raises(KeyError, match=r"^\('bar', 'three'\)$"):
         df.loc[("bar", "three"), "B"]
 
     # in theory should be inserting in a sorted space????