Skip to content

Commit

Permalink
TST: Test .loc #25548 for matched and unmatched indices of Series (#6…
Browse files Browse the repository at this point in the history
…0450)

* 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 <[email protected]>
  • Loading branch information
DhruvBShetty and dshettyepi authored Dec 29, 2024
1 parent 2edc7c9 commit 9cf4911
Showing 1 changed file with 20 additions and 0 deletions.
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)

0 comments on commit 9cf4911

Please sign in to comment.