Skip to content

Commit 60c44ff

Browse files
Switch to KeyError.
1 parent c8776b8 commit 60c44ff

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

pandas/core/indexing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ def _validate_key(self, key, axis: int):
966966
# slice of integers (only if in the labels)
967967
# boolean not in slice and with boolean index
968968
if isinstance(key, bool) and not is_bool_dtype(self.obj.index):
969-
raise TypeError("Boolean label can not be used without a boolean index")
969+
raise KeyError("Boolean label can not be used without a boolean index")
970970

971971
if isinstance(key, slice) and (
972972
isinstance(key.start, bool) or isinstance(key.stop, bool)

pandas/tests/frame/indexing/test_indexing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -948,9 +948,9 @@ def test_getitem_setitem_ix_bool_keyerror(self):
948948
# #2199
949949
df = DataFrame({"a": [1, 2, 3]})
950950
message = "Boolean label can not be used without a boolean index"
951-
with pytest.raises(TypeError, match=message):
951+
with pytest.raises(KeyError, match=message):
952952
df.loc[False]
953-
with pytest.raises(TypeError, match=message):
953+
with pytest.raises(KeyError, match=message):
954954
df.loc[True]
955955

956956
msg = "cannot use a single bool to index into setitem"

pandas/tests/indexing/test_loc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2091,7 +2091,7 @@ def test_loc_bool_incompatible_index_raises(self, index, frame_or_series):
20912091
message = "Boolean label can not be used without a boolean index"
20922092
if index.inferred_type != "boolean":
20932093
obj = frame_or_series(index=index)
2094-
with pytest.raises(TypeError, match=message):
2094+
with pytest.raises(KeyError, match=message):
20952095
obj.loc[True]
20962096

20972097
def test_loc_bool_should_not_raise(self, frame_or_series):

0 commit comments

Comments
 (0)