Skip to content

REGR: changed behavior in series[period].mask(foo, bar, inplace=True) #45546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v1.4.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
-

.. ---------------------------------------------------------------------------
Expand Down
5 changes: 3 additions & 2 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions pandas/tests/frame/indexing/test_where.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down