Skip to content

Commit ba0cedf

Browse files
author
OlivierLuG
committed
TST pandas-dev#20627 added tests, and take review into account
1 parent 313ba71 commit ba0cedf

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

pandas/tests/frame/test_nonunique_indexes.py

-20
Original file line numberDiff line numberDiff line change
@@ -513,23 +513,3 @@ def test_set_value_by_index(self):
513513

514514
df.iloc[:, 0] = 3
515515
tm.assert_series_equal(df.iloc[:, 1], expected)
516-
517-
518-
def test_iloc_with_boolean_operation():
519-
# GH 20627
520-
result = DataFrame([[0, 1], [2, 3], [4, 5], [6, np.nan]])
521-
result.iloc[result.index <= 2] *= 2
522-
expected = DataFrame([[0, 2], [4, 6], [8, 10], [6, np.nan]])
523-
tm.assert_frame_equal(result, expected)
524-
525-
result.iloc[result.index > 2] *= 2
526-
expected = DataFrame([[0, 2], [4, 6], [8, 10], [12, np.nan]])
527-
tm.assert_frame_equal(result, expected)
528-
529-
result.iloc[[True, True, False, False]] *= 2
530-
expected = DataFrame([[0, 4], [8, 12], [8, 10], [12, np.nan]])
531-
tm.assert_frame_equal(result, expected)
532-
533-
result.iloc[[False, False, True, True]] /= 2
534-
expected = DataFrame([[0.0, 4.0], [8.0, 12.0], [4.0, 5.0], [6.0, np.nan]])
535-
tm.assert_frame_equal(result, expected)

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():
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)