Skip to content

Commit 549ab20

Browse files
author
tp
committed
Change InterValindex set-ops eror code type
1 parent 1245f06 commit 549ab20

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

doc/source/whatsnew/v0.23.0.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ Other API Changes
312312
- Addition or subtraction of ``NaT`` from :class:`TimedeltaIndex` will return ``TimedeltaIndex`` instead of ``DatetimeIndex`` (:issue:`19124`)
313313
- :func:`DatetimeIndex.shift` and :func:`TimedeltaIndex.shift` will now raise ``NullFrequencyError`` (which subclasses ``ValueError``, which was raised in older versions) when the index object frequency is ``None`` (:issue:`19147`)
314314
- Addition and subtraction of ``NaN`` from a :class:`Series` with ``dtype='timedelta64[ns]'`` will raise a ``TypeError` instead of treating the ``NaN`` as ``NaT`` (:issue:`19274`)
315+
- Set operations (union, difference...) on :class:`IntervalIndex` with incompatible index types will now raise a ``TypeError`` rather than a ``ValueError`` (:issue:`19329`)
315316

316317
.. _whatsnew_0230.deprecations:
317318

pandas/core/indexes/interval.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,8 +1155,9 @@ def insert(self, loc, item):
11551155
def _as_like_interval_index(self, other, error_msg):
11561156
self._assert_can_do_setop(other)
11571157
other = _ensure_index(other)
1158-
if (not isinstance(other, IntervalIndex) or
1159-
self.closed != other.closed):
1158+
if not isinstance(other, IntervalIndex):
1159+
raise TypeError(error_msg)
1160+
elif self.closed != other.closed:
11601161
raise ValueError(error_msg)
11611162
return other
11621163

pandas/tests/indexes/interval/test_interval.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ def test_set_operation_errors(self, closed, op_name):
936936
# non-IntervalIndex
937937
msg = ('can only do set operations between two IntervalIndex objects '
938938
'that are closed on the same side')
939-
with tm.assert_raises_regex(ValueError, msg):
939+
with tm.assert_raises_regex(TypeError, msg):
940940
set_op(Index([1, 2, 3]))
941941

942942
# mixed closed

0 commit comments

Comments
 (0)