Skip to content

Commit 2f2db4f

Browse files
committed
DEPR: Deprecate the convert parameter completely
Previously, we weren't issuing a warning if the user happened to pass in the original default of "True", which would cause downstream code to break. Closes gh-17828.
1 parent 0f548d4 commit 2f2db4f

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

pandas/core/generic.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -2137,6 +2137,7 @@ def _take(self, indices, axis=0, convert=True, is_copy=True):
21372137
selecting rows, "1" means that we are selecting columns, etc.
21382138
convert : bool, default True
21392139
.. deprecated:: 0.21.0
2140+
In the future, negative indices will always be converted.
21402141
21412142
Whether to convert negative indices into positive ones.
21422143
For example, ``-1`` would map to the ``len(axis) - 1``.
@@ -2199,14 +2200,15 @@ class max_speed
21992200
"""
22002201

22012202
@Appender(_shared_docs['take'])
2202-
def take(self, indices, axis=0, convert=True, is_copy=True, **kwargs):
2203-
nv.validate_take(tuple(), kwargs)
2204-
2205-
if not convert:
2203+
def take(self, indices, axis=0, convert=-1, is_copy=True, **kwargs):
2204+
if convert != -1:
22062205
msg = ("The 'convert' parameter is deprecated "
22072206
"and will be removed in a future version.")
22082207
warnings.warn(msg, FutureWarning, stacklevel=2)
2208+
else:
2209+
convert = True
22092210

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

22122214
def xs(self, key, axis=0, level=None, drop_level=True):

pandas/core/sparse/series.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ def _ixs(self, i, axis=0):
386386
"""
387387
label = self.index[i]
388388
if isinstance(label, Index):
389-
return self.take(i, axis=axis, convert=True)
389+
return self.take(i, axis=axis)
390390
else:
391391
return self._get_val_at(i)
392392

@@ -628,14 +628,15 @@ def sparse_reindex(self, new_index):
628628
fill_value=self.fill_value).__finalize__(self)
629629

630630
@Appender(generic._shared_docs['take'])
631-
def take(self, indices, axis=0, convert=True, *args, **kwargs):
632-
convert = nv.validate_take_with_convert(convert, args, kwargs)
633-
634-
if not convert:
631+
def take(self, indices, axis=0, convert=None, *args, **kwargs):
632+
if convert is not None:
635633
msg = ("The 'convert' parameter is deprecated "
636634
"and will be removed in a future version.")
637635
warnings.warn(msg, FutureWarning, stacklevel=2)
636+
else:
637+
convert = True
638638

639+
nv.validate_take_with_convert(convert, args, kwargs)
639640
new_values = SparseArray.take(self.values, indices)
640641
new_index = self.index.take(indices)
641642
return self._constructor(new_values,

pandas/tests/frame/test_axis_select_reindex.py

+4
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,10 @@ def test_take(self):
852852
expected = df.reindex(df.index.take(order))
853853
assert_frame_equal(result, expected)
854854

855+
with tm.assert_produces_warning(FutureWarning):
856+
result = df.take(order, convert=True, axis=0)
857+
assert_frame_equal(result, expected)
858+
855859
with tm.assert_produces_warning(FutureWarning):
856860
result = df.take(order, convert=False, axis=0)
857861
assert_frame_equal(result, expected)

pandas/tests/sparse/test_series.py

+3
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,9 @@ def _compare(idx):
528528
exp = pd.Series(np.repeat(nan, 5))
529529
tm.assert_series_equal(sp.take([0, 1, 2, 3, 4]), exp)
530530

531+
with tm.assert_produces_warning(FutureWarning):
532+
sp.take([1, 5], convert=True)
533+
531534
with tm.assert_produces_warning(FutureWarning):
532535
sp.take([1, 5], convert=False)
533536

0 commit comments

Comments
 (0)