Skip to content
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

TST: Test .loc #25548 for matched and unmatched indices of Series #60450

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
20 changes: 20 additions & 0 deletions pandas/tests/indexing/test_loc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3297,3 +3297,23 @@ def test_loc_reindexing_of_empty_index(self):
df.loc[Series([False] * 4, index=df.index, name=0), 0] = df[0]
expected = DataFrame(index=[1, 1, 2, 2], data=["1", "1", "2", "2"])
tm.assert_frame_equal(df, expected)

def test_loc_setitem_matching_index(self):
# GH 25548
s = Series(0.0, index=list("abcd"))
s1 = Series(1.0, index=list("ab"))
s2 = Series(2.0, index=list("xy"))

# Test matching indices
s.loc[["a", "b"]] = s1

result = s[["a", "b"]]
expected = s1
tm.assert_series_equal(result, expected)

# Test unmatched indices
s.loc[["a", "b"]] = s2

result = s[["a", "b"]]
expected = Series([np.nan, np.nan], index=["a", "b"])
tm.assert_series_equal(result, expected)
Loading