@@ -368,9 +368,6 @@ class Index(IndexOpsMixin, PandasObject):
368
368
Index([1, 2, 3], dtype='uint8')
369
369
"""
370
370
371
- # To hand over control to subclasses
372
- _join_precedence = 1
373
-
374
371
# similar to __array_priority__, positions Index after Series and DataFrame
375
372
# but before ExtensionArray. Should NOT be overridden by subclasses.
376
373
__pandas_priority__ = 2000
@@ -4564,6 +4561,7 @@ def join(
4564
4561
Index([1, 2, 3, 4, 5, 6], dtype='int64')
4565
4562
"""
4566
4563
other = ensure_index (other )
4564
+ sort = sort or how == "outer"
4567
4565
4568
4566
if isinstance (self , ABCDatetimeIndex ) and isinstance (other , ABCDatetimeIndex ):
4569
4567
if (self .tz is None ) ^ (other .tz is None ):
@@ -4614,15 +4612,6 @@ def join(
4614
4612
rindexer = np .array ([])
4615
4613
return join_index , None , rindexer
4616
4614
4617
- if self ._join_precedence < other ._join_precedence :
4618
- flip : dict [JoinHow , JoinHow ] = {"right" : "left" , "left" : "right" }
4619
- how = flip .get (how , how )
4620
- join_index , lidx , ridx = other .join (
4621
- self , how = how , level = level , return_indexers = True
4622
- )
4623
- lidx , ridx = ridx , lidx
4624
- return join_index , lidx , ridx
4625
-
4626
4615
if self .dtype != other .dtype :
4627
4616
dtype = self ._find_common_type_compat (other )
4628
4617
this = self .astype (dtype , copy = False )
@@ -4666,18 +4655,20 @@ def _join_via_get_indexer(
4666
4655
# Note: at this point we have checked matching dtypes
4667
4656
4668
4657
if how == "left" :
4669
- join_index = self
4658
+ join_index = self . sort_values () if sort else self
4670
4659
elif how == "right" :
4671
- join_index = other
4660
+ join_index = other . sort_values () if sort else other
4672
4661
elif how == "inner" :
4673
4662
join_index = self .intersection (other , sort = sort )
4674
4663
elif how == "outer" :
4675
- # TODO: sort=True here for backwards compat. It may
4676
- # be better to use the sort parameter passed into join
4677
- join_index = self .union (other )
4678
-
4679
- if sort and how in ["left" , "right" ]:
4680
- join_index = join_index .sort_values ()
4664
+ try :
4665
+ join_index = self .union (other , sort = sort )
4666
+ except TypeError :
4667
+ join_index = self .union (other )
4668
+ try :
4669
+ join_index = _maybe_try_sort (join_index , sort )
4670
+ except TypeError :
4671
+ pass
4681
4672
4682
4673
if join_index is self :
4683
4674
lindexer = None
0 commit comments