Skip to content

Commit b126b75

Browse files
committed
Check is_bool_indexer when key is from DataFrame
1 parent 050deb6 commit b126b75

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

pandas/core/indexing.py

+6-14
Original file line numberDiff line numberDiff line change
@@ -1979,27 +1979,19 @@ def _ensure_listlike_indexer(self, key):
19791979
"""
19801980
column_axis = 1
19811981

1982-
# check if self.obj is at least 2-dimensional
1983-
if len(self.obj.shape) <= column_axis:
1982+
# column only exists in 2-dimensional DataFrame
1983+
if self.ndim != 2:
19841984
return
19851985

19861986
if isinstance(key, tuple):
1987-
# key is a _LocIndexer key
1988-
1989-
if not (
1990-
# key indexes multiple columns
1991-
is_list_like_indexer(key[column_axis])
1992-
and not com.is_bool_indexer(key[column_axis])
1993-
):
1994-
return
1995-
1996-
# set key to the column part of key which is a list-like of column
1997-
# labels
1987+
# key may be a tuple if key is a _LocIndexer key
1988+
# in that case, set key to the column part of key
19981989
key = key[column_axis]
19991990

20001991
if (
20011992
not isinstance(self.obj._get_axis(column_axis), ABCMultiIndex)
2002-
and is_list_like(key)
1993+
and is_list_like_indexer(key)
1994+
and not com.is_bool_indexer(key)
20031995
and all(is_hashable(k) for k in key)
20041996
):
20051997
for k in key:

0 commit comments

Comments
 (0)