Repository: pandas-dev/pandas

Issue:
BUG: pandas.cut should disallow overlapping IntervalIndex bins
#### Code Sample, a copy-pastable example if possible

```python
In [2]: ii = pd.IntervalIndex.from_tuples([(0, 10), (2, 12), (4, 14)])

In [3]: pd.cut([5, 6], bins=ii)
Out[3]:
[(0, 10], (2, 12], (4, 14], (0, 10], (2, 12], (4, 14]]
Categories (3, interval[int64]): [(0, 10] < (2, 12] < (4, 14]]
```
#### Problem description
When an overlapping `IntervalIndex` is provided for `bins`, all intervals overlapping a given point will be returned for that point.  I don't think this behavior makes sense.

#### Expected Output
I'd expect a `ValueError` to be raised, or at the very least for this behavior to be documented if it's intended.

I think this should be straightforward to implement once `IntervalIndex.is_overlapping` has been completed, which should be soon assuming there aren't any major issues with the PR (xref #23327).

If I'm not mistaken, it should just be just a matter of modifying this block of code:
https://github.com/pandas-dev/pandas/blob/30c1290610c65d53bcdd1665be3104104ca27eb2/pandas/core/reshape/tile.py#L219-L220
And make it check if the bins are overlapping:
```python
elif isinstance(bins, IntervalIndex):
    if bins.is_overlapping:
        raise ValueError(...)    
```

#### Output of ``pd.show_versions()``

<details>

INSTALLED VERSIONS
------------------
commit: 30c1290610c65d53bcdd1665be3104104ca27eb2
python: 3.6.1.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 78 Stepping 3, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None

pandas: 0.24.0.dev0+1141.g30c129061
pytest: 3.8.2
pip: 9.0.1
setuptools: 39.0.1
Cython: 0.28.2
numpy: 1.13.3
scipy: 1.0.0
pyarrow: 0.6.0
xarray: 0.9.6
IPython: 6.1.0
sphinx: 1.5.6
patsy: 0.4.1
dateutil: 2.6.0
pytz: 2017.2
blosc: None
bottleneck: 1.2.1
tables: 3.4.2
numexpr: 2.6.4
feather: 0.4.0
matplotlib: 2.0.2
openpyxl: 2.4.8
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 0.9.8
lxml: 3.8.0
bs4: None
html5lib: 0.999
sqlalchemy: 1.1.13
pymysql: None
psycopg2: None
jinja2: 2.9.6
s3fs: None
fastparquet: 0.1.5
pandas_gbq: None
pandas_datareader: None
gcsfs: None

</details>



Discussion:
i would like to pick this up!
Thanks @charlesdong1991 : the `IntervalIndex.is_overlapping` PR has been merged, so this should be clear to work on when you have the time.

Resolving patch:
diff --git a/pandas/core/reshape/tile.py b/pandas/core/reshape/tile.py
--- a/pandas/core/reshape/tile.py
+++ b/pandas/core/reshape/tile.py
@@ -43,7 +43,8 @@ def cut(x, bins, right=True, labels=None, retbins=False, precision=3,
           and maximum values of `x`.
         * sequence of scalars : Defines the bin edges allowing for non-uniform
           width. No extension of the range of `x` is done.
-        * IntervalIndex : Defines the exact bins to be used.
+        * IntervalIndex : Defines the exact bins to be used. Note that
+          IntervalIndex for `bins` must be non-overlapping.
 
     right : bool, default True
         Indicates whether `bins` includes the rightmost edge or not. If
@@ -217,7 +218,9 @@ def cut(x, bins, right=True, labels=None, retbins=False, precision=3,
                 bins[-1] += adj
 
     elif isinstance(bins, IntervalIndex):
-        pass
+        if bins.is_overlapping:
+            raise ValueError('Overlapping IntervalIndex is not accepted.')
+
     else:
         bins = np.asarray(bins)
         bins = _convert_bin_to_numeric_type(bins, dtype)


Test patch:
diff --git a/pandas/tests/reshape/test_tile.py b/pandas/tests/reshape/test_tile.py
--- a/pandas/tests/reshape/test_tile.py
+++ b/pandas/tests/reshape/test_tile.py
@@ -91,6 +91,12 @@ def test_bins_from_intervalindex(self):
         tm.assert_numpy_array_equal(result.codes,
                                     np.array([1, 1, 2], dtype='int8'))
 
+    def test_bins_not_overlapping_from_intervalindex(self):
+        # verify if issue 23980 is properly solved.
+        ii = IntervalIndex.from_tuples([(0, 10), (2, 12), (4, 14)])
+        with pytest.raises(ValueError):
+            cut([5, 6], bins=ii)
+
     def test_bins_not_monotonic(self):
         data = [.2, 1.4, 2.5, 6.2, 9.7, 2.1]
         pytest.raises(ValueError, cut, data, [0.1, 1.5, 1, 10])