|
11 | 11 |
|
12 | 12 | import numpy as np |
13 | 13 |
|
14 | | -from pandas._libs import Timestamp, algos, hashtable as htable, iNaT, lib |
| 14 | +from pandas._libs import algos, hashtable as htable, iNaT, lib |
15 | 15 | from pandas._typing import AnyArrayLike, ArrayLike, DtypeObj, FrameOrSeriesUnion |
16 | 16 | from pandas.util._decorators import doc |
17 | 17 |
|
|
59 | 59 | ) |
60 | 60 | from pandas.core.dtypes.missing import isna, na_value_for_dtype |
61 | 61 |
|
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 | +) |
63 | 67 | from pandas.core.indexers import validate_indices |
64 | 68 |
|
65 | 69 | if TYPE_CHECKING: |
@@ -1906,10 +1910,7 @@ def searchsorted(arr, value, side="left", sorter=None) -> np.ndarray: |
1906 | 1910 | ): |
1907 | 1911 | # E.g. if `arr` is an array with dtype='datetime64[ns]' |
1908 | 1912 | # 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) |
1913 | 1914 |
|
1914 | 1915 | result = arr.searchsorted(value, side=side, sorter=sorter) |
1915 | 1916 | return result |
|
0 commit comments