Skip to content

Commit f1ffc5f

Browse files
authored
REF: multi_take is now able to tackle all list-like (non-bool) cases (#21569)
1 parent 1638331 commit f1ffc5f

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

pandas/core/indexing.py

+28-13
Original file line numberDiff line numberDiff line change
@@ -902,30 +902,45 @@ def _getitem_tuple(self, tup):
902902
return retval
903903

904904
def _multi_take_opportunity(self, tup):
905-
from pandas.core.generic import NDFrame
905+
"""
906+
Check whether there is the possibility to use ``_multi_take``.
907+
Currently the limit is that all axes being indexed must be indexed with
908+
list-likes.
906909
907-
# ugly hack for GH #836
908-
if not isinstance(self.obj, NDFrame):
909-
return False
910+
Parameters
911+
----------
912+
tup : tuple
913+
Tuple of indexers, one per axis
910914
915+
Returns
916+
-------
917+
boolean: Whether the current indexing can be passed through _multi_take
918+
"""
911919
if not all(is_list_like_indexer(x) for x in tup):
912920
return False
913921

914922
# just too complicated
915-
for indexer, ax in zip(tup, self.obj._data.axes):
916-
if isinstance(ax, MultiIndex):
917-
return False
918-
elif com.is_bool_indexer(indexer):
919-
return False
920-
elif not ax.is_unique:
921-
return False
923+
if any(com.is_bool_indexer(x) for x in tup):
924+
return False
922925

923926
return True
924927

925928
def _multi_take(self, tup):
926-
""" create the reindex map for our objects, raise the _exception if we
927-
can't create the indexer
928929
"""
930+
Create the indexers for the passed tuple of keys, and execute the take
931+
operation. This allows the take operation to be executed all at once -
932+
rather than once for each dimension - improving efficiency.
933+
934+
Parameters
935+
----------
936+
tup : tuple
937+
Tuple of indexers, one per axis
938+
939+
Returns
940+
-------
941+
values: same type as the object being indexed
942+
"""
943+
# GH 836
929944
o = self.obj
930945
d = {axis: self._get_listlike_indexer(key, axis)
931946
for (key, axis) in zip(tup, o._AXIS_ORDERS)}

0 commit comments

Comments
 (0)