@@ -4567,22 +4567,9 @@ def _join_non_unique(
4567
4567
)
4568
4568
mask = left_idx == - 1
4569
4569
4570
- join_array = self ._values .take (left_idx )
4571
- right = other ._values .take (right_idx )
4572
-
4573
- if isinstance (join_array , np .ndarray ):
4574
- # error: Argument 3 to "putmask" has incompatible type
4575
- # "Union[ExtensionArray, ndarray[Any, Any]]"; expected
4576
- # "Union[_SupportsArray[dtype[Any]], _NestedSequence[
4577
- # _SupportsArray[dtype[Any]]], bool, int, float, complex,
4578
- # str, bytes, _NestedSequence[Union[bool, int, float,
4579
- # complex, str, bytes]]]"
4580
- np .putmask (join_array , mask , right ) # type: ignore[arg-type]
4581
- else :
4582
- join_array ._putmask (mask , right )
4583
-
4584
- join_index = self ._wrap_joined_index (join_array , other )
4585
-
4570
+ join_idx = self .take (left_idx )
4571
+ right = other .take (right_idx )
4572
+ join_index = join_idx .putmask (mask , right )
4586
4573
return join_index , left_idx , right_idx
4587
4574
4588
4575
@final
@@ -4744,8 +4731,8 @@ def _join_monotonic(
4744
4731
ret_index = other if how == "right" else self
4745
4732
return ret_index , None , None
4746
4733
4747
- ridx : np .ndarray | None
4748
- lidx : np .ndarray | None
4734
+ ridx : npt . NDArray [ np .intp ] | None
4735
+ lidx : npt . NDArray [ np .intp ] | None
4749
4736
4750
4737
if self .is_unique and other .is_unique :
4751
4738
# We can perform much better than the general case
@@ -4759,10 +4746,10 @@ def _join_monotonic(
4759
4746
ridx = None
4760
4747
elif how == "inner" :
4761
4748
join_array , lidx , ridx = self ._inner_indexer (other )
4762
- join_index = self ._wrap_joined_index (join_array , other )
4749
+ join_index = self ._wrap_joined_index (join_array , other , lidx , ridx )
4763
4750
elif how == "outer" :
4764
4751
join_array , lidx , ridx = self ._outer_indexer (other )
4765
- join_index = self ._wrap_joined_index (join_array , other )
4752
+ join_index = self ._wrap_joined_index (join_array , other , lidx , ridx )
4766
4753
else :
4767
4754
if how == "left" :
4768
4755
join_array , lidx , ridx = self ._left_indexer (other )
@@ -4773,20 +4760,33 @@ def _join_monotonic(
4773
4760
elif how == "outer" :
4774
4761
join_array , lidx , ridx = self ._outer_indexer (other )
4775
4762
4776
- join_index = self ._wrap_joined_index (join_array , other )
4763
+ assert lidx is not None
4764
+ assert ridx is not None
4765
+
4766
+ join_index = self ._wrap_joined_index (join_array , other , lidx , ridx )
4777
4767
4778
4768
lidx = None if lidx is None else ensure_platform_int (lidx )
4779
4769
ridx = None if ridx is None else ensure_platform_int (ridx )
4780
4770
return join_index , lidx , ridx
4781
4771
4782
- def _wrap_joined_index (self : _IndexT , joined : ArrayLike , other : _IndexT ) -> _IndexT :
4772
+ def _wrap_joined_index (
4773
+ self : _IndexT ,
4774
+ joined : ArrayLike ,
4775
+ other : _IndexT ,
4776
+ lidx : npt .NDArray [np .intp ],
4777
+ ridx : npt .NDArray [np .intp ],
4778
+ ) -> _IndexT :
4783
4779
assert other .dtype == self .dtype
4784
4780
4785
4781
if isinstance (self , ABCMultiIndex ):
4786
4782
name = self .names if self .names == other .names else None
4787
4783
# error: Incompatible return value type (got "MultiIndex",
4788
4784
# expected "_IndexT")
4789
- return self ._constructor (joined , name = name ) # type: ignore[return-value]
4785
+ mask = lidx == - 1
4786
+ join_idx = self .take (lidx )
4787
+ right = other .take (ridx )
4788
+ join_index = join_idx .putmask (mask , right )
4789
+ return join_index .set_names (name ) # type: ignore[return-value]
4790
4790
else :
4791
4791
name = get_op_result_name (self , other )
4792
4792
return self ._constructor ._with_infer (joined , name = name , dtype = self .dtype )
0 commit comments