@@ -2326,7 +2326,7 @@ def intersection(self, other):
2326
2326
taken .name = None
2327
2327
return taken
2328
2328
2329
- def difference (self , other ):
2329
+ def difference (self , other , sort = True ):
2330
2330
"""
2331
2331
Return a new Index with elements from the index that are not in
2332
2332
`other`.
@@ -2366,14 +2366,15 @@ def difference(self, other):
2366
2366
label_diff = np .setdiff1d (np .arange (this .size ), indexer ,
2367
2367
assume_unique = True )
2368
2368
the_diff = this .values .take (label_diff )
2369
- try :
2370
- the_diff = sorting .safe_sort (the_diff )
2371
- except TypeError :
2372
- pass
2369
+ if sort :
2370
+ try :
2371
+ the_diff = sorting .safe_sort (the_diff )
2372
+ except TypeError :
2373
+ pass
2373
2374
2374
2375
return this ._shallow_copy (the_diff , name = result_name , freq = None )
2375
2376
2376
- def symmetric_difference (self , other , result_name = None ):
2377
+ def symmetric_difference (self , other , result_name = None , sort = True ):
2377
2378
"""
2378
2379
Compute the symmetric difference of two Index objects.
2379
2380
It's sorted if sorting is possible.
@@ -2426,10 +2427,11 @@ def symmetric_difference(self, other, result_name=None):
2426
2427
right_diff = other .values .take (right_indexer )
2427
2428
2428
2429
the_diff = _concat ._concat_compat ([left_diff , right_diff ])
2429
- try :
2430
- the_diff = sorting .safe_sort (the_diff )
2431
- except TypeError :
2432
- pass
2430
+ if sort :
2431
+ try :
2432
+ the_diff = sorting .safe_sort (the_diff )
2433
+ except TypeError :
2434
+ pass
2433
2435
2434
2436
attribs = self ._get_attributes_dict ()
2435
2437
attribs ['name' ] = result_name
@@ -4220,3 +4222,4 @@ def _trim_front(strings):
4220
4222
def _validate_join_method (method ):
4221
4223
if method not in ['left' , 'right' , 'inner' , 'outer' ]:
4222
4224
raise ValueError ('do not recognize join method %s' % method )
4225
+
0 commit comments