Skip to content

Commit 9cf4911

Browse files
TST: Test .loc #25548 for matched and unmatched indices of Series (#60450)
* Added test for .loc to test setitem on matching indices * precommit workflow * modified from np.NaN to np.nan * formatting fixes * Added result and expected variables * Added result and expected variables for both tests --------- Co-authored-by: dshettyepi <dhruv.shetty@epicode.in>
1 parent 2edc7c9 commit 9cf4911

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

pandas/tests/indexing/test_loc.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3297,3 +3297,23 @@ def test_loc_reindexing_of_empty_index(self):
32973297
df.loc[Series([False] * 4, index=df.index, name=0), 0] = df[0]
32983298
expected = DataFrame(index=[1, 1, 2, 2], data=["1", "1", "2", "2"])
32993299
tm.assert_frame_equal(df, expected)
3300+
3301+
def test_loc_setitem_matching_index(self):
3302+
# GH 25548
3303+
s = Series(0.0, index=list("abcd"))
3304+
s1 = Series(1.0, index=list("ab"))
3305+
s2 = Series(2.0, index=list("xy"))
3306+
3307+
# Test matching indices
3308+
s.loc[["a", "b"]] = s1
3309+
3310+
result = s[["a", "b"]]
3311+
expected = s1
3312+
tm.assert_series_equal(result, expected)
3313+
3314+
# Test unmatched indices
3315+
s.loc[["a", "b"]] = s2
3316+
3317+
result = s[["a", "b"]]
3318+
expected = Series([np.nan, np.nan], index=["a", "b"])
3319+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)