Description
Pandas version checks
-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of pandas.
-
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
import pandas as pd
data = [pd.Interval(pd.Timestamp('2020-05-26'), pd.Timestamp('2020-05-27')),
pd.Interval(pd.Timestamp('2020-05-27'), pd.Timestamp('2020-05-27'))]
index = pd.IntervalIndex(data)
index.drop(index[0])
Traceback (most recent call last):
File "report.py", line 10, in <module>
index.drop(index[0])
File ".venv/lib/python3.10/site-packages/pandas/core/indexes/base.py", line 6930, in drop
indexer = self.get_indexer_for(labels)
File "/.venv/lib/python3.10/site-packages/pandas/core/indexes/base.py", line 6052, in get_indexer_for
return self.get_indexer(target)
File ".venv/lib/python3.10/site-packages/pandas/core/indexes/base.py", line 3973, in get_indexer
return self._get_indexer(target, method, limit, tolerance)
File ".venv/lib/python3.10/site-packages/pandas/core/indexes/interval.py", line 685, in _get_indexer
indexer = self._get_indexer_unique_sides(target)
File ".venv/lib/python3.10/site-packages/pandas/core/indexes/interval.py", line 738, in _get_indexer_unique_sides
right_indexer = self.right.get_indexer(target.right)
File ".venv/lib/python3.10/site-packages/pandas/core/indexes/base.py", line 3904, in get_indexer
raise InvalidIndexError(self._requires_unique_msg)
pandas.errors.InvalidIndexError: Reindexing only valid with uniquely valued Index objects
Issue Description
Dropping an element from an IntervalIndex
containing zero-length intervals raises an InvalidIndexError
claiming Reindexing only valid with uniquely valued Index objects
. Yet, index.is_unique
returns true
.
This sees to be related to #49581 . This is different from #38051 because it does not contain duplicates.
Expected Behavior
The first element of the index should be dropped without complaining.
Alternatively update the documentation to say when and why errors can be expected and what exactly happens if errors=ignore
is supplied. Also reference that option in the InvalidIndexError
message.