From 0321b11eb7253a6d05b26119f089055088a91109 Mon Sep 17 00:00:00 2001 From: Brock Date: Fri, 21 Jan 2022 17:57:22 -0800 Subject: [PATCH 1/2] REGR: changed behavior in series[period].mask(foo, bar, inplace=True) --- pandas/core/internals/blocks.py | 5 +++-- pandas/tests/frame/indexing/test_where.py | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index 733211a671137..3d4f53530b89c 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -1417,8 +1417,6 @@ def where(self, other, cond) -> list[Block]: # isinstance(values, NDArrayBackedExtensionArray) if isinstance(self.dtype, PeriodDtype): # TODO: don't special-case - # Note: this is the main place where the fallback logic - # is different from EABackedBlock.putmask. raise blk = self.coerce_to_target_dtype(other) nbs = blk.where(other, cond) @@ -1459,6 +1457,9 @@ def putmask(self, mask, new) -> list[Block]: elif isinstance(self, NDArrayBackedExtensionBlock): # NB: not (yet) the same as # isinstance(values, NDArrayBackedExtensionArray) + if isinstance(self.dtype, PeriodDtype): + # TODO: don't special-case + raise blk = self.coerce_to_target_dtype(new) return blk.putmask(mask, new) diff --git a/pandas/tests/frame/indexing/test_where.py b/pandas/tests/frame/indexing/test_where.py index 794153040273e..399318a6d6118 100644 --- a/pandas/tests/frame/indexing/test_where.py +++ b/pandas/tests/frame/indexing/test_where.py @@ -899,6 +899,9 @@ def test_where_period_invalid_na(frame_or_series, as_cat, request): with pytest.raises(TypeError, match=msg): obj.mask(mask, tdnat) + with pytest.raises(TypeError, match=msg): + obj.mask(mask, tdnat, inplace=True) + def test_where_nullable_invalid_na(frame_or_series, any_numeric_ea_dtype): # GH#44697 From 431dc34da5ee696493ff6804c67566b8c12f9b45 Mon Sep 17 00:00:00 2001 From: Brock Date: Sat, 22 Jan 2022 12:05:53 -0800 Subject: [PATCH 2/2] whatsnew --- doc/source/whatsnew/v1.4.1.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.4.1.rst b/doc/source/whatsnew/v1.4.1.rst index f321aabc0a8a5..48b62637c26b1 100644 --- a/doc/source/whatsnew/v1.4.1.rst +++ b/doc/source/whatsnew/v1.4.1.rst @@ -14,7 +14,7 @@ including other versions of pandas. Fixed regressions ~~~~~~~~~~~~~~~~~ -- +- Regression in :meth:`Series.mask` with ``inplace=True`` and ``PeriodDtype`` and an incompatible ``other`` coercing to a common dtype instead of raising (:issue:`45546`) - .. ---------------------------------------------------------------------------