Repository: pandas-dev/pandas

Issue:
Too generic Exception in multindex reindex raise statement
#### Code Sample, a copy-pastable example if possible
```python
import pandas as pd, numpy as np

idx = pd.MultiIndex.from_tuples([(0, 0), (1, 1), (1, 1), (2, 2)])
a = pd.Series(np.arange(4), index=idx)
new_idx = pd.MultiIndex.from_tuples([(0, 0), (1, 1), (2, 2)])
a.reindex(new_idx)
```
```python-traceback
(...)  
 2094                 else:
-> 2095                     raise Exception("cannot handle a non-unique multi-index!")
   2096 
   2097         if not isinstance(target, MultiIndex):

Exception: cannot handle a non-unique multi-index!
```
#### Problem description

```python
class MultiIndex(Index):
    (...)
    def reindex(self, target, method=None, level=None, limit=None,
        tolerance=None):
        (...)
                else:
                    raise Exception("cannot handle a non-unique multi-index!")
```

In [`MultiIndex.reindex`](https://github.com/pandas-dev/pandas/blob/master/pandas/core/indexes/multi.py#L2026), this exception is too generic, and thus not easily filtered. I think it should be an `IndexError`

#### Expected Output

`raise IndexError("cannot handle a non-unique multi-index!")`

I can do a very minimal PR to fix this if needed.

#### Output of ``pd.show_versions()``

<details>

INSTALLED VERSIONS
------------------
commit: None
python: 3.6.5.final.0
python-bits: 64
OS: Linux
OS-release: 4.15.0-24-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: fr_FR.UTF-8
LOCALE: fr_FR.UTF-8

pandas: 0.23.1
pytest: 3.6.2
pip: 10.0.1
setuptools: 39.2.0
Cython: 0.28.3
numpy: 1.14.5
scipy: 1.1.0
pyarrow: None
xarray: None
IPython: 6.4.0
sphinx: None
patsy: 0.5.0
dateutil: 2.7.3
pytz: 2018.5
blosc: None
bottleneck: None
tables: 3.4.4
numexpr: 2.6.5
feather: None
matplotlib: 2.2.2
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 1.0.1
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

</details>



Discussion:
I might go with `NotImplementedError` (unless there's a reason this functionality shouldn't be supported at some point when a solid implementation is developed).
Digging a bit deeper, an `Exception` is also raised for the same reason in [`get_indexer`](https://github.com/pandas-dev/pandas/blob/master/pandas/core/indexes/multi.py#L1961) . As I understand the mater you can't reindex with a duplicate index because there's no way to choose which of the identicaly indexed rows to choose with the new index.
Same situation with a simple `Index` raises a `ValueError`:
```python
idx = pd.Index([0, 1, 1, 2])
a = pd.Series(np.arange(4), index=idx)
new_idx = pd.Index([0, 1, 2])
a.reindex(new_idx)
```

```python-traceback
~/anaconda3/envs/py36/lib/python3.6/site-packages/pandas/core/indexes/base.py in _can_reindex(self, indexer)
   3557         # trying to reindex on an axis with duplicates
   3558         if not self.is_unique and len(indexer):
-> 3559             raise ValueError("cannot reindex from a duplicate axis")
   3560 
   3561     def reindex(self, target, method=None, level=None, limit=None,

ValueError: cannot reindex from a duplicate axis
```
So maybe `ValueError` to be coherent?

Sounds reasonable to me.

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
@@ -1958,8 +1958,8 @@ def get_indexer(self, target, method=None, limit=None, tolerance=None):
                                                           tolerance=tolerance)
 
         if not self.is_unique:
-            raise Exception('Reindexing only valid with uniquely valued Index '
-                            'objects')
+            raise ValueError('Reindexing only valid with uniquely valued '
+                             'Index objects')
 
         if method == 'pad' or method == 'backfill':
             if tolerance is not None:
@@ -2023,7 +2023,7 @@ def reindex(self, target, method=None, level=None, limit=None,
                                                limit=limit,
                                                tolerance=tolerance)
                 else:
-                    raise Exception("cannot handle a non-unique multi-index!")
+                    raise ValueError("cannot handle a non-unique multi-index!")
 
         if not isinstance(target, MultiIndex):
             if indexer is None:


Test patch:
diff --git a/pandas/tests/indexes/multi/test_reindex.py b/pandas/tests/indexes/multi/test_reindex.py
--- a/pandas/tests/indexes/multi/test_reindex.py
+++ b/pandas/tests/indexes/multi/test_reindex.py
@@ -97,3 +97,12 @@ def test_reindex_base(idx):
 
     with tm.assert_raises_regex(ValueError, 'Invalid fill method'):
         idx.get_indexer(idx, method='invalid')
+
+
+def test_reindex_non_unique():
+    idx = pd.MultiIndex.from_tuples([(0, 0), (1, 1), (1, 1), (2, 2)])
+    a = pd.Series(np.arange(4), index=idx)
+    new_idx = pd.MultiIndex.from_tuples([(0, 0), (1, 1), (2, 2)])
+    with tm.assert_raises_regex(ValueError,
+                                'cannot handle a non-unique multi-index!'):
+        a.reindex(new_idx)