From dd67df6ca0372500ccad1f0605358eeacca8c899 Mon Sep 17 00:00:00 2001 From: Daniel Saxton Date: Mon, 4 May 2020 19:03:56 -0500 Subject: [PATCH] BUG: Fix Series.update ExtensionArray issue --- doc/source/whatsnew/v1.1.0.rst | 1 + pandas/core/internals/blocks.py | 2 +- pandas/tests/series/methods/test_update.py | 24 ++++++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.1.0.rst b/doc/source/whatsnew/v1.1.0.rst index 9f9236d173dbd..00bee208906be 100644 --- a/doc/source/whatsnew/v1.1.0.rst +++ b/doc/source/whatsnew/v1.1.0.rst @@ -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 diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index d028d840448ea..e4dcffae45f67 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -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) diff --git a/pandas/tests/series/methods/test_update.py b/pandas/tests/series/methods/test_update.py index 98959599569a9..9cb6d8f81fff7 100644 --- a/pandas/tests/series/methods/test_update.py +++ b/pandas/tests/series/methods/test_update.py @@ -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)