Skip to content

Commit 31628b3

Browse files
authored
REF: re-remove _putmask_preserve (#44346)
1 parent 545db6b commit 31628b3

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

pandas/core/array_algos/putmask.py

+4-10
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ def putmask_smart(values: np.ndarray, mask: npt.NDArray[np.bool_], new) -> np.nd
126126

127127
if values.dtype.kind == new.dtype.kind:
128128
# preserves dtype if possible
129-
return _putmask_preserve(values, new, mask)
129+
np.putmask(values, mask, new)
130+
return values
130131

131132
dtype = find_common_type([values.dtype, new.dtype])
132133
# error: Argument 1 to "astype" of "_ArrayOrScalarCommon" has incompatible type
@@ -135,15 +136,8 @@ def putmask_smart(values: np.ndarray, mask: npt.NDArray[np.bool_], new) -> np.nd
135136
# List[Any], _DTypeDict, Tuple[Any, Any]]]"
136137
values = values.astype(dtype) # type: ignore[arg-type]
137138

138-
return _putmask_preserve(values, new, mask)
139-
140-
141-
def _putmask_preserve(new_values: np.ndarray, new, mask: npt.NDArray[np.bool_]):
142-
try:
143-
new_values[mask] = new[mask]
144-
except (IndexError, ValueError):
145-
new_values[mask] = new
146-
return new_values
139+
np.putmask(values, mask, new)
140+
return values
147141

148142

149143
def putmask_without_repeat(

0 commit comments

Comments
 (0)