Skip to content

Commit 5b07b53

Browse files
authored
REGR: changed behavior in series[period].mask(foo, bar, inplace=True) (#45546)
1 parent 490c586 commit 5b07b53

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

doc/source/whatsnew/v1.4.1.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ including other versions of pandas.
1414

1515
Fixed regressions
1616
~~~~~~~~~~~~~~~~~
17-
-
17+
- Regression in :meth:`Series.mask` with ``inplace=True`` and ``PeriodDtype`` and an incompatible ``other`` coercing to a common dtype instead of raising (:issue:`45546`)
1818
-
1919

2020
.. ---------------------------------------------------------------------------

pandas/core/internals/blocks.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1417,8 +1417,6 @@ def where(self, other, cond) -> list[Block]:
14171417
# isinstance(values, NDArrayBackedExtensionArray)
14181418
if isinstance(self.dtype, PeriodDtype):
14191419
# TODO: don't special-case
1420-
# Note: this is the main place where the fallback logic
1421-
# is different from EABackedBlock.putmask.
14221420
raise
14231421
blk = self.coerce_to_target_dtype(other)
14241422
nbs = blk.where(other, cond)
@@ -1459,6 +1457,9 @@ def putmask(self, mask, new) -> list[Block]:
14591457
elif isinstance(self, NDArrayBackedExtensionBlock):
14601458
# NB: not (yet) the same as
14611459
# isinstance(values, NDArrayBackedExtensionArray)
1460+
if isinstance(self.dtype, PeriodDtype):
1461+
# TODO: don't special-case
1462+
raise
14621463
blk = self.coerce_to_target_dtype(new)
14631464
return blk.putmask(mask, new)
14641465

pandas/tests/frame/indexing/test_where.py

+3
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,9 @@ def test_where_period_invalid_na(frame_or_series, as_cat, request):
899899
with pytest.raises(TypeError, match=msg):
900900
obj.mask(mask, tdnat)
901901

902+
with pytest.raises(TypeError, match=msg):
903+
obj.mask(mask, tdnat, inplace=True)
904+
902905

903906
def test_where_nullable_invalid_na(frame_or_series, any_numeric_ea_dtype):
904907
# GH#44697

0 commit comments

Comments
 (0)