From 8a28fb05b06c40300f10d93e8839d2f8d259e8c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Aur=C3=A9lio=20Barbosa?= Date: Fri, 1 Mar 2024 20:53:16 -0300 Subject: [PATCH] TST: add test_update_raises_without_intersection on DataFrame (#55509). --- pandas/core/frame.py | 4 ++-- pandas/tests/frame/methods/test_update.py | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index adcc5ec83992a..8c09a321f9bd0 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -8788,8 +8788,8 @@ def update( rows = other.index.intersection(self.index) if rows.empty: raise ValueError( - "Update not allowed when other has no index in common with " - "this dataframe." + "Update not allowed when the index on `other` has no intersection " + "with this dataframe." ) other = other.reindex(rows) diff --git a/pandas/tests/frame/methods/test_update.py b/pandas/tests/frame/methods/test_update.py index 0bcbf7ee700c6..269b9e372bd70 100644 --- a/pandas/tests/frame/methods/test_update.py +++ b/pandas/tests/frame/methods/test_update.py @@ -222,6 +222,13 @@ def test_update_raises_on_duplicate_argument_index(self): with pytest.raises(ValueError, match="duplicate index"): df.update(other) + def test_update_raises_without_intersection(self): + # GH#55509 + df = DataFrame({"a": [1]}, index=[1]) + other = DataFrame({"a": [2]}, index=[2]) + with pytest.raises(ValueError, match="no intersection"): + df.update(other) + def test_update_on_duplicate_frame_unique_argument_index(self): # GH#55509 df = DataFrame({"a": [1, 1, 1]}, index=[1, 1, 2], dtype=np.dtype("intc"))