Skip to content

REF: multi_take is now able to tackle all list-like (non-bool) cases #21569

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

Merged
merged 2 commits into from
Jun 21, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 28 additions & 13 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -902,30 +902,45 @@ def _getitem_tuple(self, tup):
return retval

def _multi_take_opportunity(self, tup):
from pandas.core.generic import NDFrame
"""
Check whether there is the possibility to use ``_multi_take``.
Currently the limit is that all axes being indexed must be indexed with
list-likes.

# ugly hack for GH #836
if not isinstance(self.obj, NDFrame):
return False
Parameters
----------
tup : tuple
Tuple of indexers, one per axis

Returns
-------
boolean: Whether the current indexing can be passed through _multi_take
"""
if not all(is_list_like_indexer(x) for x in tup):
return False

# just too complicated
for indexer, ax in zip(tup, self.obj._data.axes):
if isinstance(ax, MultiIndex):
return False
elif com.is_bool_indexer(indexer):
return False
elif not ax.is_unique:
return False
if any(com.is_bool_indexer(x) for x in tup):
return False

return True

def _multi_take(self, tup):
""" create the reindex map for our objects, raise the _exception if we
can't create the indexer
"""
Create the indexers for the passed tuple of keys, and execute the take
operation. This allows the take operation to be executed all at once -
rather than once for each dimension - improving efficiency.

Parameters
----------
tup : tuple
Tuple of indexers, one per axis

Returns
-------
values: same type as the object being indexed
"""
# GH 836
o = self.obj
d = {axis: self._get_listlike_indexer(key, axis)
for (key, axis) in zip(tup, o._AXIS_ORDERS)}
Expand Down