@@ -259,6 +259,15 @@ def __add__(self, other):
259
259
__le__ = _indexOp ('__le__' )
260
260
__ge__ = _indexOp ('__ge__' )
261
261
262
+ def __sub__ (self , other ):
263
+ return self .diff (other )
264
+
265
+ def __and__ (self , other ):
266
+ return self .intersection (other )
267
+
268
+ def __or__ (self , other ):
269
+ return self .union (other )
270
+
262
271
def union (self , other ):
263
272
"""
264
273
Form the union of two Index objects and sorts if possible
@@ -363,8 +372,6 @@ def diff(self, other):
363
372
theDiff = sorted (set (self ) - set (otherArr ))
364
373
return Index (theDiff )
365
374
366
- __sub__ = diff
367
-
368
375
def get_loc (self , key ):
369
376
"""
370
377
Get integer location for requested label
@@ -1514,6 +1521,23 @@ def intersection(self, other):
1514
1521
uniq_tuples = sorted (set (self_tuples ) & set (other_tuples ))
1515
1522
return MultiIndex .from_arrays (zip (* uniq_tuples ), sortorder = 0 )
1516
1523
1524
+ def diff (self , other ):
1525
+ """
1526
+ Compute sorted set difference of two MultiIndex objects
1527
+
1528
+ Returns
1529
+ -------
1530
+ diff : MultiIndex
1531
+ """
1532
+ self ._assert_can_do_setop (other )
1533
+
1534
+ if self .equals (other ):
1535
+ return self [:0 ]
1536
+
1537
+ difference = sorted (set (self .values ) - set (other .values ))
1538
+ return MultiIndex .from_tuples (difference , sortorder = 0 ,
1539
+ names = self .names )
1540
+
1517
1541
def _assert_can_do_setop (self , other ):
1518
1542
if not isinstance (other , MultiIndex ):
1519
1543
raise TypeError ('can only call with other hierarchical '
0 commit comments