@@ -368,9 +368,6 @@ class Index(IndexOpsMixin, PandasObject):
368368 Index([1, 2, 3], dtype='uint8')
369369 """
370370
371- # To hand over control to subclasses
372- _join_precedence = 1
373-
374371 # similar to __array_priority__, positions Index after Series and DataFrame
375372 # but before ExtensionArray. Should NOT be overridden by subclasses.
376373 __pandas_priority__ = 2000
@@ -4564,6 +4561,7 @@ def join(
45644561 Index([1, 2, 3, 4, 5, 6], dtype='int64')
45654562 """
45664563 other = ensure_index (other )
4564+ sort = sort or how == "outer"
45674565
45684566 if isinstance (self , ABCDatetimeIndex ) and isinstance (other , ABCDatetimeIndex ):
45694567 if (self .tz is None ) ^ (other .tz is None ):
@@ -4614,15 +4612,6 @@ def join(
46144612 rindexer = np .array ([])
46154613 return join_index , None , rindexer
46164614
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-
46264615 if self .dtype != other .dtype :
46274616 dtype = self ._find_common_type_compat (other )
46284617 this = self .astype (dtype , copy = False )
@@ -4666,18 +4655,20 @@ def _join_via_get_indexer(
46664655 # Note: at this point we have checked matching dtypes
46674656
46684657 if how == "left" :
4669- join_index = self
4658+ join_index = self . sort_values () if sort else self
46704659 elif how == "right" :
4671- join_index = other
4660+ join_index = other . sort_values () if sort else other
46724661 elif how == "inner" :
46734662 join_index = self .intersection (other , sort = sort )
46744663 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
46814672
46824673 if join_index is self :
46834674 lindexer = None
0 commit comments