Skip to content

WIP BUG: Warning for incompatible type when type should be compatible #56360

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 3 additions & 2 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

# ----------------------------------------------------------------------
Expand Down
9 changes: 8 additions & 1 deletion pandas/tests/series/methods/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would currently upcast, but at least there's a futurewarning noting that it won't in the future

([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),
Expand Down Expand Up @@ -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)