Skip to content

Commit e1ee2b0

Browse files
authored
BUG: Fix Series.update ExtensionArray issue (#33984)
1 parent de8ca78 commit e1ee2b0

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

doc/source/whatsnew/v1.1.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,7 @@ ExtensionArray
758758
- Fixed bug where :meth:`Series.value_counts` would raise on empty input of ``Int64`` dtype (:issue:`33317`)
759759
- Fixed bug in :class:`Series` construction with EA dtype and index but no data or scalar data fails (:issue:`26469`)
760760
- Fixed bug that caused :meth:`Series.__repr__()` to crash for extension types whose elements are multidimensional arrays (:issue:`33770`).
761+
- Fixed bug where :meth:`Series.update` would raise a ``ValueError`` for ``ExtensionArray`` dtypes with missing values (:issue:`33980`)
761762
- Fixed bug where :meth:`StringArray.memory_usage` was not implemented (:issue:`33963`)
762763

763764

pandas/core/internals/blocks.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1599,7 +1599,7 @@ def putmask(
15991599

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

1602-
if isinstance(new, np.ndarray) and len(new) == len(mask):
1602+
if isinstance(new, (np.ndarray, ExtensionArray)) and len(new) == len(mask):
16031603
new = new[mask]
16041604

16051605
mask = _safe_reshape(mask, new_values.shape)

pandas/tests/series/methods/test_update.py

+24
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,27 @@ def test_update_from_non_series(self, series, other, expected):
7474
# GH 33215
7575
series.update(other)
7676
tm.assert_series_equal(series, expected)
77+
78+
@pytest.mark.parametrize(
79+
"result, target, expected",
80+
[
81+
(
82+
Series(["a", None], dtype="string"),
83+
Series([None, "b"], dtype="string"),
84+
Series(["a", "b"], dtype="string"),
85+
),
86+
(
87+
Series([1, None], dtype="Int64"),
88+
Series([None, 2], dtype="Int64"),
89+
Series([1, 2], dtype="Int64"),
90+
),
91+
(
92+
Series([True, None], dtype="boolean"),
93+
Series([None, False], dtype="boolean"),
94+
Series([True, False], dtype="boolean"),
95+
),
96+
],
97+
)
98+
def test_update_extension_array_series(self, result, target, expected):
99+
result.update(target)
100+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)