We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c0ae870 commit a1f342dCopy full SHA for a1f342d
pandas/tests/frame/test_api.py
@@ -402,3 +402,22 @@ def test_inspect_getmembers(self):
402
# GH38740
403
df = DataFrame()
404
inspect.getmembers(df)
405
+
406
+ def test_setitem_series_alignment_documentation(self):
407
+ # Test that Series assignment aligns by index as documented.
408
+ df = DataFrame({"A": [1, 2, 3]}, index=[0, 1, 2])
409
+ s = Series([10, 20], index=[1, 3])
410
+ df["B"] = s
411
+ expected = DataFrame({"A": [1, 2, 3], "B": [np.nan, 10, np.nan]})
412
+ tm.assert_frame_equal(df, expected)
413
414
+ def test_setitem_series_partial_alignment(self):
415
+ # Test Series assignment with partial index match. """
416
+ df = DataFrame({"A": [1, 2, 3, 4]}, index=["a", "b", "c", "d"])
417
+ s = Series([100, 200], index=["b", "d"])
418
419
+ expected = DataFrame(
420
+ {"A": [1, 2, 3, 4], "B": [np.nan, 100, np.nan, 200]},
421
+ index=["a", "b", "c", "d"],
422
+ )
423
0 commit comments