Skip to content

Commit 0d79e2f

Browse files
jbrockmendelmeeseeksmachine
authored andcommitted
Backport PR pandas-dev#45546: REGR: changed behavior in series[period].mask(foo, bar, inplace=True)
1 parent d716efd commit 0d79e2f

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
@@ -1376,8 +1376,6 @@ def where(self, other, cond) -> list[Block]:
13761376
# isinstance(values, NDArrayBackedExtensionArray)
13771377
if isinstance(self.dtype, PeriodDtype):
13781378
# TODO: don't special-case
1379-
# Note: this is the main place where the fallback logic
1380-
# is different from EABackedBlock.putmask.
13811379
raise
13821380
blk = self.coerce_to_target_dtype(other)
13831381
nbs = blk.where(other, cond)
@@ -1418,6 +1416,9 @@ def putmask(self, mask, new) -> list[Block]:
14181416
elif isinstance(self, NDArrayBackedExtensionBlock):
14191417
# NB: not (yet) the same as
14201418
# isinstance(values, NDArrayBackedExtensionArray)
1419+
if isinstance(self.dtype, PeriodDtype):
1420+
# TODO: don't special-case
1421+
raise
14211422
blk = self.coerce_to_target_dtype(new)
14221423
return blk.putmask(mask, new)
14231424

pandas/tests/frame/indexing/test_where.py

+3
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,9 @@ def test_where_period_invalid_na(frame_or_series, as_cat, request):
892892
with pytest.raises(TypeError, match=msg):
893893
obj.mask(mask, tdnat)
894894

895+
with pytest.raises(TypeError, match=msg):
896+
obj.mask(mask, tdnat, inplace=True)
897+
895898

896899
def test_where_nullable_invalid_na(frame_or_series, any_numeric_ea_dtype):
897900
# GH#44697

0 commit comments

Comments
 (0)