Skip to content

Commit 2481063

Browse files
committed
reformatted tests
1 parent 1c92fc8 commit 2481063

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

pandas/tests/indexing/test_iloc.py

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -742,26 +742,6 @@ def test_iloc_mask(self):
742742
result = df.iloc[np.array([True] * len(mask), dtype=bool)]
743743
tm.assert_frame_equal(result, df)
744744

745-
result = df.iloc[np.array([True, False, True, False, True], dtype=bool)]
746-
tm.assert_frame_equal(
747-
result, DataFrame({"a": [0, 2, 4]}, index=["A", "C", "E"])
748-
)
749-
750-
# series (index does not match)
751-
msg = "Unalignable boolean Series provided as indexer"
752-
with pytest.raises(IndexingError, match=msg):
753-
df.iloc[Series([True] * len(mask), dtype=bool)]
754-
755-
df = DataFrame(list(range(5)), columns=["a"])
756-
757-
result = df.iloc[Series([True] * len(mask), dtype=bool)]
758-
tm.assert_frame_equal(result, df)
759-
760-
result = df.iloc[Series([True, False, True, False, True], dtype=bool)]
761-
tm.assert_frame_equal(result, DataFrame({"a": [0, 2, 4]}, index=[0, 2, 4]))
762-
763-
df = DataFrame(list(range(5)), index=list("ABCDE"), columns=["a"])
764-
765745
# the possibilities
766746
locs = np.arange(4)
767747
nums = 2**locs
@@ -817,6 +797,32 @@ def test_iloc_mask(self):
817797
# For error messages, substring match is sufficient
818798
assert expected_result in answer, f"[{key}] not found in [{answer}]"
819799

800+
def test_iloc_with_numpy_bool_array(self):
801+
df = DataFrame(list(range(5)), index=list("ABCDE"), columns=["a"])
802+
result = df.iloc[np.array([True, False, True, False, True], dtype=bool)]
803+
expected = DataFrame({"a": [0, 2, 4]}, index=["A", "C", "E"])
804+
tm.assert_frame_equal(result, expected)
805+
806+
def test_iloc_series_mask_with_index_mismatch_raises(self):
807+
df = DataFrame(list(range(5)), index=list("ABCDE"), columns=["a"])
808+
mask = df.a % 2 == 0
809+
msg = "Unalignable boolean Series provided as indexer"
810+
with pytest.raises(IndexingError, match=msg):
811+
df.iloc[Series([True] * len(mask), dtype=bool)]
812+
813+
def test_iloc_series_mask_all_true(self):
814+
df = DataFrame(list(range(5)), columns=["a"])
815+
mask = Series([True] * len(df), dtype=bool)
816+
result = df.iloc[mask]
817+
tm.assert_frame_equal(result, df)
818+
819+
def test_iloc_series_mask_alternate_true(self):
820+
df = DataFrame(list(range(5)), columns=["a"])
821+
mask = Series([True, False, True, False, True], dtype=bool)
822+
result = df.iloc[mask]
823+
expected = DataFrame({"a": [0, 2, 4]}, index=[0, 2, 4])
824+
tm.assert_frame_equal(result, expected)
825+
820826
def test_iloc_non_unique_indexing(self):
821827
# GH 4017, non-unique indexing (on the axis)
822828
df = DataFrame({"A": [0.1] * 3000, "B": [1] * 3000})

0 commit comments

Comments
 (0)