Skip to content

Commit 9895311

Browse files
authored
REF: dont dispatch Block.putmask to Block.where (#44457)
1 parent 1b887ec commit 9895311

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

pandas/core/internals/blocks.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
Shape,
3131
npt,
3232
)
33+
from pandas.compat import np_version_under1p20
3334
from pandas.util._decorators import cache_readonly
3435
from pandas.util._exceptions import find_stack_level
3536
from pandas.util._validators import validate_bool_kwarg
@@ -969,16 +970,15 @@ def putmask(self, mask, new) -> list[Block]:
969970
putmask_without_repeat(values.T, mask, new)
970971
return [self]
971972

972-
elif noop:
973-
return [self]
974-
975-
dtype, _ = infer_dtype_from(new)
976-
if dtype.kind in ["m", "M"]:
973+
elif np_version_under1p20 and infer_dtype_from(new)[0].kind in ["m", "M"]:
977974
# using putmask with object dtype will incorrectly cast to object
978975
# Having excluded self._can_hold_element, we know we cannot operate
979976
# in-place, so we are safe using `where`
980977
return self.where(new, ~mask)
981978

979+
elif noop:
980+
return [self]
981+
982982
elif self.ndim == 1 or self.shape[0] == 1:
983983
# no need to split columns
984984

0 commit comments

Comments
 (0)