@@ -705,6 +705,25 @@ def test_iloc_setitem_categorical_updates_inplace(self):
705
705
expected = pd .Categorical (["C" , "B" , "A" ])
706
706
tm .assert_categorical_equal (cat , expected )
707
707
708
+ def test_iloc_with_boolean_operation ():
709
+ # GH 20627
710
+ result = DataFrame ([[0 , 1 ], [2 , 3 ], [4 , 5 ], [6 , np .nan ]])
711
+ result .iloc [result .index <= 2 ] *= 2
712
+ expected = DataFrame ([[0 , 2 ], [4 , 6 ], [8 , 10 ], [6 , np .nan ]])
713
+ tm .assert_frame_equal (result , expected )
714
+
715
+ result .iloc [result .index > 2 ] *= 2
716
+ expected = DataFrame ([[0 , 2 ], [4 , 6 ], [8 , 10 ], [12 , np .nan ]])
717
+ tm .assert_frame_equal (result , expected )
718
+
719
+ result .iloc [[True , True , False , False ]] *= 2
720
+ expected = DataFrame ([[0 , 4 ], [8 , 12 ], [8 , 10 ], [12 , np .nan ]])
721
+ tm .assert_frame_equal (result , expected )
722
+
723
+ result .iloc [[False , False , True , True ]] /= 2
724
+ expected = DataFrame ([[0.0 , 4.0 ], [8.0 , 12.0 ], [4.0 , 5.0 ], [6.0 , np .nan ]])
725
+ tm .assert_frame_equal (result , expected )
726
+
708
727
709
728
class TestILocSetItemDuplicateColumns :
710
729
def test_iloc_setitem_scalar_duplicate_columns (self ):
0 commit comments