Skip to content

BUG: Fix Series.update ExtensionArray issue #33984

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 2 commits into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,7 @@ ExtensionArray
- Fixed bug where :meth:`Series.value_counts` would raise on empty input of ``Int64`` dtype (:issue:`33317`)
- Fixed bug in :class:`Series` construction with EA dtype and index but no data or scalar data fails (:issue:`26469`)
- Fixed bug that caused :meth:`Series.__repr__()` to crash for extension types whose elements are multidimensional arrays (:issue:`33770`).
- Fixed bug where :meth:`Series.update` would raise a ``ValueError`` for ``ExtensionArray`` dtypes with missing values (:issue:`33980`)


Other
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1599,7 +1599,7 @@ def putmask(

new_values = self.values if inplace else self.values.copy()

if isinstance(new, np.ndarray) and len(new) == len(mask):
if isinstance(new, (np.ndarray, ExtensionArray)) and len(new) == len(mask):
new = new[mask]

mask = _safe_reshape(mask, new_values.shape)
Expand Down
24 changes: 24 additions & 0 deletions pandas/tests/series/methods/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,27 @@ def test_update_from_non_series(self, series, other, expected):
# GH 33215
series.update(other)
tm.assert_series_equal(series, expected)

@pytest.mark.parametrize(
"result, target, expected",
[
(
Series(["a", None], dtype="string"),
Series([None, "b"], dtype="string"),
Series(["a", "b"], dtype="string"),
),
(
Series([1, None], dtype="Int64"),
Series([None, 2], dtype="Int64"),
Series([1, 2], dtype="Int64"),
),
(
Series([True, None], dtype="boolean"),
Series([None, False], dtype="boolean"),
Series([True, False], dtype="boolean"),
),
],
)
def test_update_extension_array_series(self, result, target, expected):
result.update(target)
tm.assert_series_equal(result, expected)