Skip to content

Commit 2e90c7f

Browse files
authored
TST: boolean indexing using .iloc #20627 (#34622)
* added a test for issue #20627 * added a test for issue #20627 (review taken into account) * TST: boolean indexing using .iloc #20627 * TST #20627 added tests, and take review into account * Updated test_iloc.py to pass CI testing
1 parent aaf4b7b commit 2e90c7f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

pandas/tests/indexing/test_iloc.py

+19
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,25 @@ def test_iloc_setitem_categorical_updates_inplace(self):
705705
expected = pd.Categorical(["C", "B", "A"])
706706
tm.assert_categorical_equal(cat, expected)
707707

708+
def test_iloc_with_boolean_operation(self):
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+
708727

709728
class TestILocSetItemDuplicateColumns:
710729
def test_iloc_setitem_scalar_duplicate_columns(self):

0 commit comments

Comments
 (0)