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 6 commits into
base: main
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions pandas/tests/indexing/test_loc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3297,3 +3297,22 @@ 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, series_with_simple_index):
# GH 25548
ser1 = series_with_simple_index.copy()
ser1 = ser1[~ser1.index.duplicated(keep="first")]
ser2 = ser1.copy()
# Testing on upto 2 indices
for nsize in range(1, min(len(ser1), 3)):
random_sample = ser1.sample(n=nsize)
matching_mask = ser1.index.isin(random_sample.index)
# Remove values at indices to test assignment
ser1.loc[matching_mask] = np.nan
ser1.loc[matching_mask] = random_sample
tm.assert_series_equal(ser1, ser2)
# exclude row and index and test assignment of unmatched indices
exclude_mask = ~matching_mask
ser2.loc[matching_mask] = ser1.loc[exclude_mask]
ser1.loc[matching_mask] = np.nan
tm.assert_series_equal(ser2, ser1)
Loading