Skip to content

Commit 03c05c8

Browse files
author
Yi Wei
committed
ENH: Enable using a boolean loc in a non-boolean index
1 parent 961f9c4 commit 03c05c8

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

pandas/core/indexing.py

+12-11
Original file line numberDiff line numberDiff line change
@@ -1127,15 +1127,16 @@ def _validate_key(self, key, axis: Axis):
11271127
# slice of integers (only if in the labels)
11281128
# boolean not in slice and with boolean index
11291129
ax = self.obj._get_axis(axis)
1130-
if isinstance(key, bool) and not (
1131-
is_bool_dtype(ax.dtype)
1132-
or ax.dtype.name == "boolean"
1133-
or isinstance(ax, MultiIndex)
1134-
and is_bool_dtype(ax.get_level_values(0).dtype)
1135-
):
1136-
raise KeyError(
1137-
f"{key}: boolean label can not be used without a boolean index"
1138-
)
1130+
1131+
# if isinstance(key, bool) and not (
1132+
# is_bool_dtype(ax.dtype)
1133+
# or ax.dtype.name == "boolean"
1134+
# or isinstance(ax, MultiIndex)
1135+
# and is_bool_dtype(ax.get_level_values(0).dtype)
1136+
# ):
1137+
# raise KeyError(
1138+
# f"{key}: boolean label can not be used without a boolean index"
1139+
# )
11391140

11401141
if isinstance(key, slice) and (
11411142
isinstance(key.start, bool) or isinstance(key.stop, bool)
@@ -1306,8 +1307,8 @@ def _getitem_axis(self, key, axis: AxisInt):
13061307
if isinstance(key, slice):
13071308
self._validate_key(key, axis)
13081309
return self._get_slice_axis(key, axis=axis)
1309-
elif com.is_bool_indexer(key):
1310-
return self._getbool_axis(key, axis=axis)
1310+
# elif com.is_bool_indexer(key):
1311+
# return self._getbool_axis(key, axis=axis)
13111312
elif is_list_like_indexer(key):
13121313
# an iterable multi-selection
13131314
if not (isinstance(key, tuple) and isinstance(labels, MultiIndex)):

0 commit comments

Comments
 (0)