From fd91ae83853823b114938a73f03ff696899d5354 Mon Sep 17 00:00:00 2001 From: MarcoGorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Wed, 6 Dec 2023 11:53:11 +0000 Subject: [PATCH] wip Series.update pdep6-issue --- pandas/core/series.py | 5 +++-- pandas/tests/series/methods/test_update.py | 9 ++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 464e066b4e86a..ce61edee5c8d2 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -3598,10 +3598,11 @@ def update(self, other: Series | Sequence | Mapping) -> None: if not isinstance(other, Series): other = Series(other) - other = other.reindex_like(self) + other = other.loc[other.index.isin(self.index)] mask = notna(other) - self._mgr = self._mgr.putmask(mask=mask, new=other) + indexer = self.index._get_indexer(other.index[mask]) + self._set_values(indexer, other[mask]._values) self._maybe_update_cacher() # ---------------------------------------------------------------------- diff --git a/pandas/tests/series/methods/test_update.py b/pandas/tests/series/methods/test_update.py index 3f18ae6c13880..4817dd9d822ca 100644 --- a/pandas/tests/series/methods/test_update.py +++ b/pandas/tests/series/methods/test_update.py @@ -46,7 +46,7 @@ def test_update(self, using_copy_on_write): "other, dtype, expected, warn", [ # other is int - ([61, 63], "int32", Series([10, 61, 12], dtype="int32"), None), + ([61, 63], "int32", Series([10, 61, 12]), FutureWarning), ([61, 63], "int64", Series([10, 61, 12]), None), ([61, 63], float, Series([10.0, 61.0, 12.0]), None), ([61, 63], object, Series([10, 61, 12], dtype=object), None), @@ -137,3 +137,10 @@ def test_update_with_categorical_type(self): result = s1 expected = Series(["b", "a", "c"], index=[1, 2, 3], dtype=dtype) tm.assert_series_equal(result, expected) + + def test_update_with_bool_type(self): + # https://github.com/pandas-dev/pandas/issues/55990 + s = Series([True, True], index=["a", "b"]) + s.update({"a": False}) + expected = Series([False, True], index=["a", "b"]) + tm.assert_series_equal(s, expected)