Skip to content

Commit fd91ae8

Browse files
committed
wip Series.update pdep6-issue
1 parent fce7760 commit fd91ae8

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

pandas/core/series.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3598,10 +3598,11 @@ def update(self, other: Series | Sequence | Mapping) -> None:
35983598
if not isinstance(other, Series):
35993599
other = Series(other)
36003600

3601-
other = other.reindex_like(self)
3601+
other = other.loc[other.index.isin(self.index)]
36023602
mask = notna(other)
36033603

3604-
self._mgr = self._mgr.putmask(mask=mask, new=other)
3604+
indexer = self.index._get_indexer(other.index[mask])
3605+
self._set_values(indexer, other[mask]._values)
36053606
self._maybe_update_cacher()
36063607

36073608
# ----------------------------------------------------------------------

pandas/tests/series/methods/test_update.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def test_update(self, using_copy_on_write):
4646
"other, dtype, expected, warn",
4747
[
4848
# other is int
49-
([61, 63], "int32", Series([10, 61, 12], dtype="int32"), None),
49+
([61, 63], "int32", Series([10, 61, 12]), FutureWarning),
5050
([61, 63], "int64", Series([10, 61, 12]), None),
5151
([61, 63], float, Series([10.0, 61.0, 12.0]), None),
5252
([61, 63], object, Series([10, 61, 12], dtype=object), None),
@@ -137,3 +137,10 @@ def test_update_with_categorical_type(self):
137137
result = s1
138138
expected = Series(["b", "a", "c"], index=[1, 2, 3], dtype=dtype)
139139
tm.assert_series_equal(result, expected)
140+
141+
def test_update_with_bool_type(self):
142+
# https://github.com/pandas-dev/pandas/issues/55990
143+
s = Series([True, True], index=["a", "b"])
144+
s.update({"a": False})
145+
expected = Series([False, True], index=["a", "b"])
146+
tm.assert_series_equal(s, expected)

0 commit comments

Comments
 (0)