Skip to content

Commit

Permalink
DEPR: Deprecate the convert parameter completely
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gfyoung committed Oct 11, 2017
1 parent 727ea20 commit 762fd6e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
10 changes: 6 additions & 4 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2172,6 +2172,7 @@ def _take(self, indices, axis=0, convert=True, is_copy=True):
selecting rows, "1" means that we are selecting columns, etc.
convert : bool, default True
.. deprecated:: 0.21.0
In the future, negative indices will always be converted.
Whether to convert negative indices into positive ones.
For example, ``-1`` would map to the ``len(axis) - 1``.
Expand Down Expand Up @@ -2234,14 +2235,15 @@ class max_speed
"""

@Appender(_shared_docs['take'])
def take(self, indices, axis=0, convert=True, is_copy=True, **kwargs):
nv.validate_take(tuple(), kwargs)

if not convert:
def take(self, indices, axis=0, convert=-1, is_copy=True, **kwargs):
if convert is not -1:
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)

def xs(self, key, axis=0, level=None, drop_level=True):
Expand Down
11 changes: 6 additions & 5 deletions pandas/core/sparse/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ def _ixs(self, i, axis=0):
"""
label = self.index[i]
if isinstance(label, Index):
return self.take(i, axis=axis, convert=True)
return self.take(i, axis=axis)
else:
return self._get_val_at(i)

Expand Down Expand Up @@ -629,14 +629,15 @@ def sparse_reindex(self, new_index):
fill_value=self.fill_value).__finalize__(self)

@Appender(generic._shared_docs['take'])
def take(self, indices, axis=0, convert=True, *args, **kwargs):
convert = nv.validate_take_with_convert(convert, args, kwargs)

if not convert:
def take(self, indices, axis=0, convert=-1, *args, **kwargs):
if convert is not -1:
msg = ("The 'convert' parameter is deprecated "
"and will be removed in a future version.")
warnings.warn(msg, FutureWarning, stacklevel=2)
else:
convert = True

nv.validate_take_with_convert(convert, args, kwargs)
new_values = SparseArray.take(self.values, indices)
new_index = self.index.take(indices)
return self._constructor(new_values,
Expand Down
4 changes: 4 additions & 0 deletions pandas/tests/frame/test_axis_select_reindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,10 @@ def test_take(self):
expected = df.reindex(df.index.take(order))
assert_frame_equal(result, expected)

with tm.assert_produces_warning(FutureWarning):
result = df.take(order, convert=True, axis=0)
assert_frame_equal(result, expected)

with tm.assert_produces_warning(FutureWarning):
result = df.take(order, convert=False, axis=0)
assert_frame_equal(result, expected)
Expand Down
3 changes: 3 additions & 0 deletions pandas/tests/sparse/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,9 @@ def _compare(idx):
exp = pd.Series(np.repeat(nan, 5))
tm.assert_series_equal(sp.take([0, 1, 2, 3, 4]), exp)

with tm.assert_produces_warning(FutureWarning):
sp.take([1, 5], convert=True)

with tm.assert_produces_warning(FutureWarning):
sp.take([1, 5], convert=False)

Expand Down

0 comments on commit 762fd6e

Please sign in to comment.