From e0b209b65a10dadbb10b82148865d7255f3cfb57 Mon Sep 17 00:00:00 2001 From: gfyoung Date: Sat, 23 Sep 2017 02:18:04 -0700 Subject: [PATCH] MAINT: .take() --> ._take() --- pandas/core/frame.py | 8 ++++---- pandas/core/generic.py | 10 +++++----- pandas/core/groupby.py | 8 ++++---- pandas/core/indexing.py | 18 ++++++++++-------- 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 47955b5e5cfee0..67115740c3cc26 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -2032,7 +2032,7 @@ def _ixs(self, i, axis=0): return self.loc[:, lab_slice] else: if isinstance(label, Index): - return self.take(i, axis=1) + return self._take(i, axis=1, convert=True) index_len = len(self.index) @@ -2114,10 +2114,10 @@ def _getitem_array(self, key): # be reindexed to match DataFrame rows key = check_bool_indexer(self.index, key) indexer = key.nonzero()[0] - return self.take(indexer, axis=0) + return self._take(indexer, axis=0, convert=False) else: indexer = self.loc._convert_to_indexer(key, axis=1) - return self.take(indexer, axis=1) + return self._take(indexer, axis=1, convert=True) def _getitem_multilevel(self, key): loc = self.columns.get_loc(key) @@ -3349,7 +3349,7 @@ def dropna(self, axis=0, how='any', thresh=None, subset=None, else: raise TypeError('must specify how or thresh') - result = self.take(mask.nonzero()[0], axis=axis) + result = self._take(mask.nonzero()[0], axis=axis, convert=False) if inplace: self._update_inplace(result) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index b9dde0f6293b5b..0b5253386bebdf 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1821,7 +1821,7 @@ def _iget_item_cache(self, item): if ax.is_unique: lower = self._get_item_cache(ax[item]) else: - lower = self.take(item, axis=self._info_axis_number) + lower = self._take(item, axis=self._info_axis_number, convert=True) return lower def _box_item_values(self, key, values): @@ -2299,9 +2299,9 @@ def xs(self, key, axis=0, level=None, drop_level=True): if isinstance(loc, np.ndarray): if loc.dtype == np.bool_: inds, = loc.nonzero() - return self.take(inds, axis=axis) + return self._take(inds, axis=axis, convert=False) else: - return self.take(loc, axis=axis) + return self._take(loc, axis=axis, convert=True) if not is_scalar(loc): new_index = self.index[loc] @@ -5114,7 +5114,7 @@ def at_time(self, time, asof=False): """ try: indexer = self.index.indexer_at_time(time, asof=asof) - return self.take(indexer) + return self._take(indexer, convert=False) except AttributeError: raise TypeError('Index must be DatetimeIndex') @@ -5138,7 +5138,7 @@ def between_time(self, start_time, end_time, include_start=True, indexer = self.index.indexer_between_time( start_time, end_time, include_start=include_start, include_end=include_end) - return self.take(indexer) + return self._take(indexer, convert=False) except AttributeError: raise TypeError('Index must be DatetimeIndex') diff --git a/pandas/core/groupby.py b/pandas/core/groupby.py index fddfc2db4472ec..8cb90c9dfea3fc 100644 --- a/pandas/core/groupby.py +++ b/pandas/core/groupby.py @@ -319,8 +319,8 @@ def _set_grouper(self, obj, sort=False): # use stable sort to support first, last, nth indexer = self.indexer = ax.argsort(kind='mergesort') ax = ax.take(indexer) - obj = obj.take(indexer, axis=self.axis, - is_copy=False) + obj = obj._take(indexer, axis=self.axis, + convert=False, is_copy=False) self.obj = obj self.grouper = ax @@ -643,7 +643,7 @@ def get_group(self, name, obj=None): if not len(inds): raise KeyError(name) - return obj.take(inds, axis=self.axis) + return obj._take(inds, axis=self.axis, convert=False) def __iter__(self): """ @@ -2202,7 +2202,7 @@ def _aggregate_series_fast(self, obj, func): # avoids object / Series creation overhead dummy = obj._get_values(slice(None, 0)).to_dense() indexer = get_group_index_sorter(group_index, ngroups) - obj = obj.take(indexer).to_dense() + obj = obj._take(indexer, convert=False).to_dense() group_index = algorithms.take_nd( group_index, indexer, allow_fill=False) grouper = lib.SeriesGrouper(obj, func, group_index, ngroups, diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index 55539fc760042f..faaf82726ce368 100755 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -1093,7 +1093,7 @@ def _getitem_iterable(self, key, axis=0): if is_bool_indexer(key): key = check_bool_indexer(labels, key) inds, = key.nonzero() - return self.obj.take(inds, axis=axis) + return self.obj._take(inds, axis=axis, convert=False) else: # Have the index compute an indexer or return None # if it cannot handle; we only act on all found values @@ -1126,14 +1126,15 @@ def _getitem_iterable(self, key, axis=0): keyarr) if new_indexer is not None: - result = self.obj.take(indexer[indexer != -1], axis=axis) + result = self.obj._take(indexer[indexer != -1], axis=axis, + convert=False) result = result._reindex_with_indexers( {axis: [new_target, new_indexer]}, copy=True, allow_dups=True) else: - result = self.obj.take(indexer, axis=axis) + result = self.obj._take(indexer, axis=axis, convert=False) return result @@ -1264,7 +1265,7 @@ def _get_slice_axis(self, slice_obj, axis=0): if isinstance(indexer, slice): return self._slice(indexer, axis=axis, kind='iloc') else: - return self.obj.take(indexer, axis=axis) + return self.obj._take(indexer, axis=axis, convert=False) class _IXIndexer(_NDFrameIndexer): @@ -1348,8 +1349,9 @@ def _getbool_axis(self, key, axis=0): labels = self.obj._get_axis(axis) key = check_bool_indexer(labels, key) inds, = key.nonzero() + try: - return self.obj.take(inds, axis=axis) + return self.obj._take(inds, axis=axis, convert=False) except Exception as detail: raise self._exception(detail) @@ -1366,7 +1368,7 @@ def _get_slice_axis(self, slice_obj, axis=0): if isinstance(indexer, slice): return self._slice(indexer, axis=axis, kind='iloc') else: - return self.obj.take(indexer, axis=axis) + return self.obj._take(indexer, axis=axis, convert=False) class _LocIndexer(_LocationIndexer): @@ -1706,7 +1708,7 @@ def _get_slice_axis(self, slice_obj, axis=0): if isinstance(slice_obj, slice): return self._slice(slice_obj, axis=axis, kind='iloc') else: - return self.obj.take(slice_obj, axis=axis) + return self.obj._take(slice_obj, axis=axis, convert=False) def _get_list_axis(self, key, axis=0): """ @@ -1722,7 +1724,7 @@ def _get_list_axis(self, key, axis=0): Series object """ try: - return self.obj.take(key, axis=axis) + return self.obj._take(key, axis=axis, convert=False) except IndexError: # re-raise with different error message raise IndexError("positional indexers are out-of-bounds")