Skip to content

Commit

Permalink
MAINT: .take() --> ._take()
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyoung committed Sep 23, 2017
1 parent 35812d0 commit e0b209b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 21 deletions.
8 changes: 4 additions & 4 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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')

Expand All @@ -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')

Expand Down
8 changes: 4 additions & 4 deletions pandas/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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,
Expand Down
18 changes: 10 additions & 8 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)

Expand All @@ -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):
Expand Down Expand Up @@ -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):
"""
Expand All @@ -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")
Expand Down

0 comments on commit e0b209b

Please sign in to comment.