Skip to content

Warn on boolean frame indexer #39373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
6 changes: 6 additions & 0 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3041,6 +3041,12 @@ def __getitem__(self, key):

# Do we have a (boolean) DataFrame?
if isinstance(key, DataFrame):
warnings.warn(
"DataFrame indexer is deprecated "
"and will be disallowed in future. Use where instead.",
FutureWarning,
stacklevel=2,
)
return self.where(key)

# Do we have a (boolean) 1d indexer?
Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/indexing/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,16 @@ def test_partial_boolean_frame_indexing(self):
)
tm.assert_frame_equal(result, expected)

def test_boolean_frame_indexing(self):
# GH 39004
df = DataFrame(
np.arange(9.0).reshape(3, 3), index=list("abc"), columns=list("ABC")
)

boolean_frame_indexer = DataFrame(True, index=list("abc"), columns=list("ABC"))
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
df[boolean_frame_indexer]

def test_no_reference_cycle(self):
df = DataFrame({"a": [0, 1], "b": [2, 3]})
for name in ("loc", "iloc", "at", "iat"):
Expand Down