Skip to content

Commit 1f4a1c9

Browse files
committed
fixed typing checks; closes issue 14833
1 parent 94f7c44 commit 1f4a1c9

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

pandas/core/indexes/multi.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3789,7 +3789,7 @@ def _reorder_indexer(
37893789
return indexer[ind]
37903790

37913791
@overload
3792-
def searchsorted(
3792+
def searchsorted( # type: ignore[overload-overlap]
37933793
self,
37943794
value: ScalarLike_co,
37953795
side: Literal["left", "right"] = ...,
@@ -3809,7 +3809,7 @@ def searchsorted(
38093809
value: NumpyValueArrayLike | ExtensionArray,
38103810
side: Literal["left", "right"] = "left",
38113811
sorter: npt.NDArray[np.intp] | None = None,
3812-
) -> np.intp | npt.NDArray[np.intp]:
3812+
) -> npt.NDArray[np.intp] | np.intp:
38133813
"""
38143814
Find the indices where elements should be inserted to maintain order.
38153815
@@ -3826,8 +3826,9 @@ def searchsorted(
38263826
38273827
Returns
38283828
-------
3829-
npt.NDArray[np.intp]
3830-
Array of insertion points.
3829+
npt.NDArray[np.intp] or np.intp
3830+
The index or indices where the value(s) should be inserted to
3831+
maintain order.
38313832
38323833
See Also
38333834
--------
@@ -3837,7 +3838,7 @@ def searchsorted(
38373838
--------
38383839
>>> mi = pd.MultiIndex.from_arrays([["a", "b", "c"], ["x", "y", "z"]])
38393840
>>> mi.searchsorted(("b", "y"))
3840-
1
3841+
array([1])
38413842
"""
38423843

38433844
if not value:
@@ -3876,7 +3877,8 @@ def searchsorted(
38763877
sorter=sorter,
38773878
)
38783879
result.append(np.intp(pos[0]))
3879-
3880+
if len(result) == 1:
3881+
return result[0]
38803882
return np.array(result, dtype=np.intp)
38813883

38823884
def truncate(self, before=None, after=None) -> MultiIndex:

0 commit comments

Comments
 (0)