Skip to content

Commit 3340f27

Browse files
toobazjreback
authored andcommitted
CLN: removed unused "convert" parameter to _take (#20934)
1 parent 2ab3727 commit 3340f27

File tree

5 files changed

+27
-42
lines changed

5 files changed

+27
-42
lines changed

pandas/core/frame.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -2641,7 +2641,7 @@ def _ixs(self, i, axis=0):
26412641
return self.loc[:, lab_slice]
26422642
else:
26432643
if isinstance(label, Index):
2644-
return self._take(i, axis=1, convert=True)
2644+
return self._take(i, axis=1)
26452645

26462646
index_len = len(self.index)
26472647

@@ -2720,10 +2720,10 @@ def _getitem_array(self, key):
27202720
# be reindexed to match DataFrame rows
27212721
key = check_bool_indexer(self.index, key)
27222722
indexer = key.nonzero()[0]
2723-
return self._take(indexer, axis=0, convert=False)
2723+
return self._take(indexer, axis=0)
27242724
else:
27252725
indexer = self.loc._convert_to_indexer(key, axis=1)
2726-
return self._take(indexer, axis=1, convert=True)
2726+
return self._take(indexer, axis=1)
27272727

27282728
def _getitem_multilevel(self, key):
27292729
loc = self.columns.get_loc(key)
@@ -4292,7 +4292,7 @@ def dropna(self, axis=0, how='any', thresh=None, subset=None,
42924292
else:
42934293
raise TypeError('must specify how or thresh')
42944294

4295-
result = self._take(mask.nonzero()[0], axis=axis, convert=False)
4295+
result = self._take(mask.nonzero()[0], axis=axis)
42964296

42974297
if inplace:
42984298
self._update_inplace(result)

pandas/core/generic.py

+8-20
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
from pandas.core.index import (Index, MultiIndex, _ensure_index,
3838
InvalidIndexError, RangeIndex)
3939
import pandas.core.indexing as indexing
40-
from pandas.core.indexing import maybe_convert_indices
4140
from pandas.core.indexes.datetimes import DatetimeIndex
4241
from pandas.core.indexes.period import PeriodIndex, Period
4342
from pandas.core.internals import BlockManager
@@ -2510,8 +2509,7 @@ def _iget_item_cache(self, item):
25102509
if ax.is_unique:
25112510
lower = self._get_item_cache(ax[item])
25122511
else:
2513-
lower = self._take(item, axis=self._info_axis_number,
2514-
convert=True)
2512+
lower = self._take(item, axis=self._info_axis_number)
25152513
return lower
25162514

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

27872780
@Appender(_shared_docs['_take'])
2788-
def _take(self, indices, axis=0, convert=True, is_copy=True):
2781+
def _take(self, indices, axis=0, is_copy=True):
27892782
self._consolidate_inplace()
27902783

2791-
if convert:
2792-
indices = maybe_convert_indices(indices, len(self._get_axis(axis)))
2793-
27942784
new_data = self._data.take(indices,
27952785
axis=self._get_block_manager_axis(axis),
27962786
verify=True)
@@ -2893,11 +2883,9 @@ def take(self, indices, axis=0, convert=None, is_copy=True, **kwargs):
28932883
msg = ("The 'convert' parameter is deprecated "
28942884
"and will be removed in a future version.")
28952885
warnings.warn(msg, FutureWarning, stacklevel=2)
2896-
else:
2897-
convert = True
28982886

2899-
convert = nv.validate_take(tuple(), kwargs)
2900-
return self._take(indices, axis=axis, convert=convert, is_copy=is_copy)
2887+
nv.validate_take(tuple(), kwargs)
2888+
return self._take(indices, axis=axis, is_copy=is_copy)
29012889

29022890
def xs(self, key, axis=0, level=None, drop_level=True):
29032891
"""
@@ -2998,9 +2986,9 @@ def xs(self, key, axis=0, level=None, drop_level=True):
29982986
if isinstance(loc, np.ndarray):
29992987
if loc.dtype == np.bool_:
30002988
inds, = loc.nonzero()
3001-
return self._take(inds, axis=axis, convert=False)
2989+
return self._take(inds, axis=axis)
30022990
else:
3003-
return self._take(loc, axis=axis, convert=True)
2991+
return self._take(loc, axis=axis)
30042992

30052993
if not is_scalar(loc):
30062994
new_index = self.index[loc]
@@ -6784,7 +6772,7 @@ def at_time(self, time, asof=False):
67846772
"""
67856773
try:
67866774
indexer = self.index.indexer_at_time(time, asof=asof)
6787-
return self._take(indexer, convert=False)
6775+
return self._take(indexer)
67886776
except AttributeError:
67896777
raise TypeError('Index must be DatetimeIndex')
67906778

@@ -6808,7 +6796,7 @@ def between_time(self, start_time, end_time, include_start=True,
68086796
indexer = self.index.indexer_between_time(
68096797
start_time, end_time, include_start=include_start,
68106798
include_end=include_end)
6811-
return self._take(indexer, convert=False)
6799+
return self._take(indexer)
68126800
except AttributeError:
68136801
raise TypeError('Index must be DatetimeIndex')
68146802

pandas/core/groupby/groupby.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -508,8 +508,7 @@ def _set_grouper(self, obj, sort=False):
508508
# use stable sort to support first, last, nth
509509
indexer = self.indexer = ax.argsort(kind='mergesort')
510510
ax = ax.take(indexer)
511-
obj = obj._take(indexer, axis=self.axis,
512-
convert=False, is_copy=False)
511+
obj = obj._take(indexer, axis=self.axis, is_copy=False)
513512

514513
self.obj = obj
515514
self.grouper = ax
@@ -860,7 +859,7 @@ def get_group(self, name, obj=None):
860859
if not len(inds):
861860
raise KeyError(name)
862861

863-
return obj._take(inds, axis=self.axis, convert=False)
862+
return obj._take(inds, axis=self.axis)
864863

865864
def __iter__(self):
866865
"""
@@ -1437,9 +1436,9 @@ def last(x):
14371436
cls.min = groupby_function('min', 'min', np.min, numeric_only=False)
14381437
cls.max = groupby_function('max', 'max', np.max, numeric_only=False)
14391438
cls.first = groupby_function('first', 'first', first_compat,
1440-
numeric_only=False, _convert=True)
1439+
numeric_only=False)
14411440
cls.last = groupby_function('last', 'last', last_compat,
1442-
numeric_only=False, _convert=True)
1441+
numeric_only=False)
14431442

14441443
@Substitution(name='groupby')
14451444
@Appender(_doc_template)
@@ -2653,7 +2652,7 @@ def _aggregate_series_fast(self, obj, func):
26532652
# avoids object / Series creation overhead
26542653
dummy = obj._get_values(slice(None, 0)).to_dense()
26552654
indexer = get_group_index_sorter(group_index, ngroups)
2656-
obj = obj._take(indexer, convert=False).to_dense()
2655+
obj = obj._take(indexer).to_dense()
26572656
group_index = algorithms.take_nd(
26582657
group_index, indexer, allow_fill=False)
26592658
grouper = reduction.SeriesGrouper(obj, func, group_index, ngroups,
@@ -5032,7 +5031,7 @@ def __iter__(self):
50325031
yield i, self._chop(sdata, slice(start, end))
50335032

50345033
def _get_sorted_data(self):
5035-
return self.data._take(self.sort_idx, axis=self.axis, convert=False)
5034+
return self.data._take(self.sort_idx, axis=self.axis)
50365035

50375036
def _chop(self, sdata, slice_obj):
50385037
return sdata.iloc[slice_obj]

pandas/core/indexing.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,7 @@ def _getitem_iterable(self, key, axis=None):
11261126
if com.is_bool_indexer(key):
11271127
key = check_bool_indexer(labels, key)
11281128
inds, = key.nonzero()
1129-
return self.obj._take(inds, axis=axis, convert=False)
1129+
return self.obj._take(inds, axis=axis)
11301130
else:
11311131
# Have the index compute an indexer or return None
11321132
# if it cannot handle; we only act on all found values
@@ -1158,8 +1158,7 @@ def _getitem_iterable(self, key, axis=None):
11581158
keyarr)
11591159

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

11641163
self._validate_read_indexer(key, new_indexer, axis)
11651164
result = result._reindex_with_indexers(
@@ -1356,7 +1355,7 @@ def _get_slice_axis(self, slice_obj, axis=None):
13561355
if isinstance(indexer, slice):
13571356
return self._slice(indexer, axis=axis, kind='iloc')
13581357
else:
1359-
return self.obj._take(indexer, axis=axis, convert=False)
1358+
return self.obj._take(indexer, axis=axis)
13601359

13611360

13621361
class _IXIndexer(_NDFrameIndexer):
@@ -1494,7 +1493,7 @@ def _getbool_axis(self, key, axis=None):
14941493
key = check_bool_indexer(labels, key)
14951494
inds, = key.nonzero()
14961495
try:
1497-
return self.obj._take(inds, axis=axis, convert=False)
1496+
return self.obj._take(inds, axis=axis)
14981497
except Exception as detail:
14991498
raise self._exception(detail)
15001499

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

15191518

15201519
class _LocIndexer(_LocationIndexer):
@@ -2050,7 +2049,7 @@ def _get_slice_axis(self, slice_obj, axis=None):
20502049
if isinstance(slice_obj, slice):
20512050
return self._slice(slice_obj, axis=axis, kind='iloc')
20522051
else:
2053-
return self.obj._take(slice_obj, axis=axis, convert=False)
2052+
return self.obj._take(slice_obj, axis=axis)
20542053

20552054
def _get_list_axis(self, key, axis=None):
20562055
"""
@@ -2068,7 +2067,7 @@ def _get_list_axis(self, key, axis=None):
20682067
if axis is None:
20692068
axis = self.axis or 0
20702069
try:
2071-
return self.obj._take(key, axis=axis, convert=False)
2070+
return self.obj._take(key, axis=axis)
20722071
except IndexError:
20732072
# re-raise with different error message
20742073
raise IndexError("positional indexers are out-of-bounds")

pandas/core/series.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -3503,16 +3503,15 @@ def memory_usage(self, index=True, deep=False):
35033503
return v
35043504

35053505
@Appender(generic._shared_docs['_take'])
3506-
def _take(self, indices, axis=0, convert=True, is_copy=False):
3507-
if convert:
3508-
indices = maybe_convert_indices(indices, len(self._get_axis(axis)))
3506+
def _take(self, indices, axis=0, is_copy=False):
35093507

35103508
indices = _ensure_platform_int(indices)
35113509
new_index = self.index.take(indices)
35123510

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

0 commit comments

Comments
 (0)