Skip to content

CLN: algos.searchsorted #38686

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions pandas/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import numpy as np

from pandas._libs import Timestamp, algos, hashtable as htable, iNaT, lib
from pandas._libs import algos, hashtable as htable, iNaT, lib
from pandas._typing import AnyArrayLike, ArrayLike, DtypeObj, FrameOrSeriesUnion
from pandas.util._decorators import doc

Expand Down Expand Up @@ -59,7 +59,11 @@
)
from pandas.core.dtypes.missing import isna, na_value_for_dtype

from pandas.core.construction import array, extract_array
from pandas.core.construction import (
array,
ensure_wrapped_if_datetimelike,
extract_array,
)
from pandas.core.indexers import validate_indices

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

result = arr.searchsorted(value, side=side, sorter=sorter)
return result
Expand Down
7 changes: 2 additions & 5 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1063,15 +1063,12 @@ def putmask(self, mask, new, axis: int = 0) -> List["Block"]:
# We only get here for non-Extension Blocks, so _try_coerce_args
# is only relevant for DatetimeBlock and TimedeltaBlock
if self.dtype.kind in ["m", "M"]:
blk = self
if not inplace:
blk = self.copy()
arr = blk.array_values()
arr = self.array_values()
arr = cast("NDArrayBackedExtensionArray", arr)
if transpose:
arr = arr.T
arr.putmask(mask, new)
return [blk]
return [self]

if lib.is_scalar(new):
new = convert_scalar_for_putitemlike(new, self.values.dtype)
Expand Down