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
16 changes: 16 additions & 0 deletions pandas/tests/indexing/test_loc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3297,3 +3297,19 @@ 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
tm.assert_series_equal(s[["a", "b"]], s1)

# Test unmatched indices
s.loc[["a", "b"]] = s2
tm.assert_series_equal(
s[["a", "b"]], Series([np.nan, np.nan], index=["a", "b"])
Copy link
Member

Choose a reason for hiding this comment

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

Could you assign result = s[["a", "b"]] and expected = Series([np.nan, np.nan], index=["a", "b"])?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure 👍

)
Loading