Skip to content

Commit 0f7a548

Browse files
committed
Added test for .loc to test setitem on matching indices
1 parent 1d809c3 commit 0f7a548

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

pandas/tests/indexing/test_loc.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3297,3 +3297,22 @@ 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,series_with_simple_index):
3302+
# GH 25548
3303+
ser1=series_with_simple_index.copy()
3304+
ser1=ser1[~ser1.index.duplicated(keep='first')]
3305+
ser2=ser1.copy()
3306+
# Testing on upto 2 indices
3307+
for nsize in range(1,min(len(ser1),3)):
3308+
random_sample=ser1.sample(n=nsize)
3309+
matching_mask=ser1.index.isin(random_sample.index)
3310+
# Remove values at indices to test assignment
3311+
ser1.loc[matching_mask]=np.NaN
3312+
ser1.loc[matching_mask]=random_sample
3313+
tm.assert_series_equal(ser1,ser2)
3314+
#exclude row and index and test assignment of unmatched indices
3315+
exclude_mask=~matching_mask
3316+
ser2.loc[matching_mask]=ser1.loc[exclude_mask]
3317+
ser1.loc[matching_mask]=np.NaN
3318+
tm.assert_series_equal(ser2,ser1)

0 commit comments

Comments
 (0)