diff --git a/pandas/core/array_algos/putmask.py b/pandas/core/array_algos/putmask.py index 24a0f83dbb313..daf7d0bd3f213 100644 --- a/pandas/core/array_algos/putmask.py +++ b/pandas/core/array_algos/putmask.py @@ -126,6 +126,8 @@ def putmask_without_repeat( mask : np.ndarray[bool] new : Any """ + new = setitem_datetimelike_compat(values, mask.sum(), new) + if getattr(new, "ndim", 0) >= 1: new = new.astype(values.dtype, copy=False) diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index ef1cd92a60540..afeaf665e1972 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -30,7 +30,6 @@ Shape, npt, ) -from pandas.compat import np_version_under1p20 from pandas.util._decorators import cache_readonly from pandas.util._exceptions import find_stack_level from pandas.util._validators import validate_bool_kwarg @@ -39,7 +38,6 @@ from pandas.core.dtypes.cast import ( can_hold_element, find_result_type, - infer_dtype_from, maybe_downcast_numeric, maybe_downcast_to_dtype, soft_convert_objects, @@ -988,12 +986,6 @@ def putmask(self, mask, new) -> list[Block]: putmask_without_repeat(values.T, mask, new) return [self] - elif np_version_under1p20 and infer_dtype_from(new)[0].kind in ["m", "M"]: - # using putmask with object dtype will incorrectly cast to object - # Having excluded self._can_hold_element, we know we cannot operate - # in-place, so we are safe using `where` - return self.where(new, ~mask) - elif noop: return [self]