Skip to content

Commit 4bfb3cb

Browse files
jbrockmendelyehoshuadimarsky
authored andcommitted
REF: remove Block.putmask fallback to where (pandas-dev#45440)
1 parent c869e66 commit 4bfb3cb

File tree

2 files changed

+2
-8
lines changed

2 files changed

+2
-8
lines changed

pandas/core/array_algos/putmask.py

+2
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ def putmask_without_repeat(
126126
mask : np.ndarray[bool]
127127
new : Any
128128
"""
129+
new = setitem_datetimelike_compat(values, mask.sum(), new)
130+
129131
if getattr(new, "ndim", 0) >= 1:
130132
new = new.astype(values.dtype, copy=False)
131133

pandas/core/internals/blocks.py

-8
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
Shape,
3131
npt,
3232
)
33-
from pandas.compat import np_version_under1p20
3433
from pandas.util._decorators import cache_readonly
3534
from pandas.util._exceptions import find_stack_level
3635
from pandas.util._validators import validate_bool_kwarg
@@ -39,7 +38,6 @@
3938
from pandas.core.dtypes.cast import (
4039
can_hold_element,
4140
find_result_type,
42-
infer_dtype_from,
4341
maybe_downcast_numeric,
4442
maybe_downcast_to_dtype,
4543
soft_convert_objects,
@@ -977,12 +975,6 @@ def putmask(self, mask, new) -> list[Block]:
977975
putmask_without_repeat(values.T, mask, new)
978976
return [self]
979977

980-
elif np_version_under1p20 and infer_dtype_from(new)[0].kind in ["m", "M"]:
981-
# using putmask with object dtype will incorrectly cast to object
982-
# Having excluded self._can_hold_element, we know we cannot operate
983-
# in-place, so we are safe using `where`
984-
return self.where(new, ~mask)
985-
986978
elif noop:
987979
return [self]
988980

0 commit comments

Comments
 (0)