From f44aaadc1e7aef04f893c0f649d2fa3b40afc952 Mon Sep 17 00:00:00 2001 From: Pietro Battiston Date: Wed, 20 Jun 2018 15:34:53 +0200 Subject: [PATCH 1/2] REF: multi_take is now able to tackle all list-like (non-bool) cases --- pandas/core/indexing.py | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index d5e81105dd323..4c8fc9efef96d 100755 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -902,23 +902,12 @@ def _getitem_tuple(self, tup): return retval def _multi_take_opportunity(self, tup): - from pandas.core.generic import NDFrame - - # ugly hack for GH #836 - if not isinstance(self.obj, NDFrame): - return False - 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 From 430a2681847c42f542c40731ef33f24f99fdc2c6 Mon Sep 17 00:00:00 2001 From: Pietro Battiston Date: Thu, 21 Jun 2018 11:36:19 +0200 Subject: [PATCH 2/2] DOC: docstrings for _multi_take --- pandas/core/indexing.py | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index 4c8fc9efef96d..cdc592ae253ac 100755 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -902,6 +902,20 @@ def _getitem_tuple(self, tup): return retval def _multi_take_opportunity(self, tup): + """ + 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. + + 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 @@ -912,9 +926,21 @@ def _multi_take_opportunity(self, tup): 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)}