Skip to content

Commit

Permalink
CLN: removed unused "convert" parameter to _take (#20934)
Browse files Browse the repository at this point in the history
  • Loading branch information
toobaz authored and jreback committed May 3, 2018
1 parent 2ab3727 commit 3340f27
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 42 deletions.
8 changes: 4 additions & 4 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2641,7 +2641,7 @@ def _ixs(self, i, axis=0):
return self.loc[:, lab_slice]
else:
if isinstance(label, Index):
return self._take(i, axis=1, convert=True)
return self._take(i, axis=1)

index_len = len(self.index)

Expand Down Expand Up @@ -2720,10 +2720,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, convert=False)
return self._take(indexer, axis=0)
else:
indexer = self.loc._convert_to_indexer(key, axis=1)
return self._take(indexer, axis=1, convert=True)
return self._take(indexer, axis=1)

def _getitem_multilevel(self, key):
loc = self.columns.get_loc(key)
Expand Down Expand Up @@ -4292,7 +4292,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, convert=False)
result = self._take(mask.nonzero()[0], axis=axis)

if inplace:
self._update_inplace(result)
Expand Down
28 changes: 8 additions & 20 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
from pandas.core.index import (Index, MultiIndex, _ensure_index,
InvalidIndexError, RangeIndex)
import pandas.core.indexing as indexing
from pandas.core.indexing import maybe_convert_indices
from pandas.core.indexes.datetimes import DatetimeIndex
from pandas.core.indexes.period import PeriodIndex, Period
from pandas.core.internals import BlockManager
Expand Down Expand Up @@ -2510,8 +2509,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,
convert=True)
lower = self._take(item, axis=self._info_axis_number)
return lower

def _box_item_values(self, key, values):
Expand Down Expand Up @@ -2765,11 +2763,6 @@ def __delitem__(self, key):
axis : int, default 0
The axis on which to select elements. "0" means that we are
selecting rows, "1" means that we are selecting columns, etc.
convert : bool, default True
Whether to convert negative indices into positive ones.
For example, ``-1`` would map to the ``len(axis) - 1``.
The conversions are similar to the behavior of indexing a
regular Python list.
is_copy : bool, default True
Whether to return a copy of the original object or not.
Expand All @@ -2785,12 +2778,9 @@ def __delitem__(self, key):
"""

@Appender(_shared_docs['_take'])
def _take(self, indices, axis=0, convert=True, is_copy=True):
def _take(self, indices, axis=0, is_copy=True):
self._consolidate_inplace()

if convert:
indices = maybe_convert_indices(indices, len(self._get_axis(axis)))

new_data = self._data.take(indices,
axis=self._get_block_manager_axis(axis),
verify=True)
Expand Down Expand Up @@ -2893,11 +2883,9 @@ def take(self, indices, axis=0, convert=None, is_copy=True, **kwargs):
msg = ("The 'convert' parameter is deprecated "
"and will be removed in a future version.")
warnings.warn(msg, FutureWarning, stacklevel=2)
else:
convert = True

convert = nv.validate_take(tuple(), kwargs)
return self._take(indices, axis=axis, convert=convert, is_copy=is_copy)
nv.validate_take(tuple(), kwargs)
return self._take(indices, axis=axis, is_copy=is_copy)

def xs(self, key, axis=0, level=None, drop_level=True):
"""
Expand Down Expand Up @@ -2998,9 +2986,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, convert=False)
return self._take(inds, axis=axis)
else:
return self._take(loc, axis=axis, convert=True)
return self._take(loc, axis=axis)

if not is_scalar(loc):
new_index = self.index[loc]
Expand Down Expand Up @@ -6784,7 +6772,7 @@ def at_time(self, time, asof=False):
"""
try:
indexer = self.index.indexer_at_time(time, asof=asof)
return self._take(indexer, convert=False)
return self._take(indexer)
except AttributeError:
raise TypeError('Index must be DatetimeIndex')

Expand All @@ -6808,7 +6796,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, convert=False)
return self._take(indexer)
except AttributeError:
raise TypeError('Index must be DatetimeIndex')

Expand Down
13 changes: 6 additions & 7 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,7 @@ 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,
convert=False, is_copy=False)
obj = obj._take(indexer, axis=self.axis, is_copy=False)

self.obj = obj
self.grouper = ax
Expand Down Expand Up @@ -860,7 +859,7 @@ def get_group(self, name, obj=None):
if not len(inds):
raise KeyError(name)

return obj._take(inds, axis=self.axis, convert=False)
return obj._take(inds, axis=self.axis)

def __iter__(self):
"""
Expand Down Expand Up @@ -1437,9 +1436,9 @@ def last(x):
cls.min = groupby_function('min', 'min', np.min, numeric_only=False)
cls.max = groupby_function('max', 'max', np.max, numeric_only=False)
cls.first = groupby_function('first', 'first', first_compat,
numeric_only=False, _convert=True)
numeric_only=False)
cls.last = groupby_function('last', 'last', last_compat,
numeric_only=False, _convert=True)
numeric_only=False)

@Substitution(name='groupby')
@Appender(_doc_template)
Expand Down Expand Up @@ -2653,7 +2652,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, convert=False).to_dense()
obj = obj._take(indexer).to_dense()
group_index = algorithms.take_nd(
group_index, indexer, allow_fill=False)
grouper = reduction.SeriesGrouper(obj, func, group_index, ngroups,
Expand Down Expand Up @@ -5032,7 +5031,7 @@ def __iter__(self):
yield i, self._chop(sdata, slice(start, end))

def _get_sorted_data(self):
return self.data._take(self.sort_idx, axis=self.axis, convert=False)
return self.data._take(self.sort_idx, axis=self.axis)

def _chop(self, sdata, slice_obj):
return sdata.iloc[slice_obj]
Expand Down
15 changes: 7 additions & 8 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,7 @@ def _getitem_iterable(self, key, axis=None):
if com.is_bool_indexer(key):
key = check_bool_indexer(labels, key)
inds, = key.nonzero()
return self.obj._take(inds, axis=axis, convert=False)
return self.obj._take(inds, axis=axis)
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 @@ -1158,8 +1158,7 @@ def _getitem_iterable(self, key, axis=None):
keyarr)

if new_indexer is not None:
result = self.obj._take(indexer[indexer != -1], axis=axis,
convert=False)
result = self.obj._take(indexer[indexer != -1], axis=axis)

self._validate_read_indexer(key, new_indexer, axis)
result = result._reindex_with_indexers(
Expand Down Expand Up @@ -1356,7 +1355,7 @@ def _get_slice_axis(self, slice_obj, axis=None):
if isinstance(indexer, slice):
return self._slice(indexer, axis=axis, kind='iloc')
else:
return self.obj._take(indexer, axis=axis, convert=False)
return self.obj._take(indexer, axis=axis)


class _IXIndexer(_NDFrameIndexer):
Expand Down Expand Up @@ -1494,7 +1493,7 @@ def _getbool_axis(self, key, axis=None):
key = check_bool_indexer(labels, key)
inds, = key.nonzero()
try:
return self.obj._take(inds, axis=axis, convert=False)
return self.obj._take(inds, axis=axis)
except Exception as detail:
raise self._exception(detail)

Expand All @@ -1514,7 +1513,7 @@ def _get_slice_axis(self, slice_obj, axis=None):
if isinstance(indexer, slice):
return self._slice(indexer, axis=axis, kind='iloc')
else:
return self.obj._take(indexer, axis=axis, convert=False)
return self.obj._take(indexer, axis=axis)


class _LocIndexer(_LocationIndexer):
Expand Down Expand Up @@ -2050,7 +2049,7 @@ def _get_slice_axis(self, slice_obj, axis=None):
if isinstance(slice_obj, slice):
return self._slice(slice_obj, axis=axis, kind='iloc')
else:
return self.obj._take(slice_obj, axis=axis, convert=False)
return self.obj._take(slice_obj, axis=axis)

def _get_list_axis(self, key, axis=None):
"""
Expand All @@ -2068,7 +2067,7 @@ def _get_list_axis(self, key, axis=None):
if axis is None:
axis = self.axis or 0
try:
return self.obj._take(key, axis=axis, convert=False)
return self.obj._take(key, axis=axis)
except IndexError:
# re-raise with different error message
raise IndexError("positional indexers are out-of-bounds")
Expand Down
5 changes: 2 additions & 3 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -3503,16 +3503,15 @@ def memory_usage(self, index=True, deep=False):
return v

@Appender(generic._shared_docs['_take'])
def _take(self, indices, axis=0, convert=True, is_copy=False):
if convert:
indices = maybe_convert_indices(indices, len(self._get_axis(axis)))
def _take(self, indices, axis=0, is_copy=False):

indices = _ensure_platform_int(indices)
new_index = self.index.take(indices)

if is_categorical_dtype(self):
# https://github.com/pandas-dev/pandas/issues/20664
# TODO: remove when the default Categorical.take behavior changes
indices = maybe_convert_indices(indices, len(self._get_axis(axis)))
kwargs = {'allow_fill': False}
else:
kwargs = {}
Expand Down

0 comments on commit 3340f27

Please sign in to comment.