Change IntervalIndex set-ops error code type by topper-123 · Pull Request #19329 · pandas-dev/pandas (original) (raw)
- xref ENH: DataFrame.append preserves columns dtype if possible #19021
- tests added / passed
- passes
git diff upstream/master -u -- "*.py" | flake8 --diff
- whatsnew entry
Set operations (union, difference...) on IntervalIndex
with incompatible index types will now raise a TypeError
rather than a ValueError
.
This PR is needed to make the changes requested in #19021.
EDIT: I've improved the error message also. Previously, you'd get:
pd.IntervalIndex.from_breaks([0,1,2,3]).union(pd.RangeIndex(3)) ValueError: can only do set operations between two IntervalIndex objects that are closed on the same side
Which made no sense in this case. Now we get:
pd.IntervalIndex.from_breaks([0,1,2,3]).union(pd.RangeIndex(3)) TypeError: the other index needs to be an IntervalIndex too, but was type RangeIndex