Skip to content

Commit 5e1b831

Browse files
keep inconsistent behaviour for MultiIndex.difference
1 parent 05a0ed0 commit 5e1b831

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

pandas/core/indexes/multi.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3007,12 +3007,7 @@ def difference(self, other, sort=None):
30073007
assume_unique=True)
30083008
difference = this.values.take(label_diff)
30093009
if sort is None:
3010-
try:
3011-
difference = sorted(difference)
3012-
except TypeError as e:
3013-
warnings.warn("{}, sort order is undefined for "
3014-
"incomparable objects".format(e),
3015-
RuntimeWarning, stacklevel=2)
3010+
difference = sorted(difference)
30163011

30173012
if len(difference) == 0:
30183013
return MultiIndex(levels=[[]] * self.nlevels,

pandas/tests/indexes/multi/test_set_ops.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,10 @@ def test_difference_sort_incomparable():
208208
other = pd.MultiIndex.from_product([[3, pd.Timestamp('2000'), 4],
209209
['c', 'd']])
210210
# sort=None, the default
211-
with tm.assert_produces_warning(RuntimeWarning):
211+
# MultiIndex.difference deviates here from other difference
212+
# implementations in not catching the TypeError
213+
with pytest.raises(TypeError):
212214
result = idx.difference(other)
213-
tm.assert_index_equal(result, idx)
214215

215216
# sort=False
216217
result = idx.difference(other, sort=False)

0 commit comments

Comments
 (0)