Skip to content

Commit d3841ad

Browse files
authored
CLN: algos.searchsorted (#38686)
1 parent d481c13 commit d3841ad

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

pandas/core/algorithms.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import numpy as np
1313

14-
from pandas._libs import Timestamp, algos, hashtable as htable, iNaT, lib
14+
from pandas._libs import algos, hashtable as htable, iNaT, lib
1515
from pandas._typing import AnyArrayLike, ArrayLike, DtypeObj, FrameOrSeriesUnion
1616
from pandas.util._decorators import doc
1717

@@ -59,7 +59,11 @@
5959
)
6060
from pandas.core.dtypes.missing import isna, na_value_for_dtype
6161

62-
from pandas.core.construction import array, extract_array
62+
from pandas.core.construction import (
63+
array,
64+
ensure_wrapped_if_datetimelike,
65+
extract_array,
66+
)
6367
from pandas.core.indexers import validate_indices
6468

6569
if TYPE_CHECKING:
@@ -1906,10 +1910,7 @@ def searchsorted(arr, value, side="left", sorter=None) -> np.ndarray:
19061910
):
19071911
# E.g. if `arr` is an array with dtype='datetime64[ns]'
19081912
# and `value` is a pd.Timestamp, we may need to convert value
1909-
value_ser = array([value]) if is_scalar(value) else array(value)
1910-
value = value_ser[0] if is_scalar(value) else value_ser
1911-
if isinstance(value, Timestamp) and value.tzinfo is None:
1912-
value = value.to_datetime64()
1913+
arr = ensure_wrapped_if_datetimelike(arr)
19131914

19141915
result = arr.searchsorted(value, side=side, sorter=sorter)
19151916
return result

0 commit comments

Comments
 (0)