@@ -3297,3 +3297,36 @@ 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_set_series_to_multiple_columns (self ):
3302+ # GH 59933
3303+ df = DataFrame ([[1 , 2 , 3 ], [4 , 5 , 6 ]], columns = list ("ABC" ))
3304+ df .loc [0 :3 , ["A" , "B" , "C" ]] = Series ([10 , 20 , 30 ])
3305+ expected = DataFrame ([[10 , 10 , 10 ], [20 , 20 , 20 ]], columns = list ("ABC" ))
3306+ tm .assert_frame_equal (df , expected )
3307+
3308+ df = DataFrame ([[1 , 2 , 3 ], [4 , 5 , 6 ]], columns = list ("ABC" ))
3309+ df .loc [:, ["A" , "B" , "C" ]] = Series ([10 , 20 , 30 ])
3310+ expected = DataFrame ([[10 , 10 , 10 ], [20 , 20 , 20 ]], columns = list ("ABC" ))
3311+ tm .assert_frame_equal (df , expected )
3312+
3313+ df = DataFrame ([[1 , 2 , 3 ], [4 , 5 , 6 ], [7 , 8 , 9 ]], columns = list ("ABC" ))
3314+ df .loc [df ["A" ] > 0 , ["A" , "B" , "C" ]] = Series ([10 , 20 , 30 ])
3315+ expected = DataFrame (
3316+ [[10 , 10 , 10 ], [20 , 20 , 20 ], [30 , 30 , 30 ]], columns = list ("ABC" )
3317+ )
3318+ tm .assert_frame_equal (df , expected )
3319+
3320+ df = DataFrame ([[1 , 2 , 3 ], [4 , 5 , 6 ], [7 , 8 , 9 ]], columns = list ("ABC" ))
3321+ df .loc [:, ["A" , "B" , "C" ]] = Series ([10 , 20 , 30 ])
3322+ expected = DataFrame (
3323+ [[10 , 10 , 10 ], [20 , 20 , 20 ], [30 , 30 , 30 ]], columns = list ("ABC" )
3324+ )
3325+ tm .assert_frame_equal (df , expected )
3326+
3327+ df = DataFrame ([[1 , 2 , 3 ], [4 , 5 , 6 ], [7 , 8 , 9 ]], columns = list ("ABC" ))
3328+ df .loc [0 :4 , ["A" , "B" , "C" ]] = Series ([10 , 20 , 30 ])
3329+ expected = DataFrame (
3330+ [[10 , 10 , 10 ], [20 , 20 , 20 ], [30 , 30 , 30 ]], columns = list ("ABC" )
3331+ )
3332+ tm .assert_frame_equal (df , expected )
0 commit comments