Skip to content

Commit

Permalink
DEPR: Deprecate Index.set_value
Browse files Browse the repository at this point in the history
  • Loading branch information
topper-123 committed Sep 25, 2019
1 parent 83eb75b commit e775378
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
4 changes: 3 additions & 1 deletion doc/source/whatsnew/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ Other API changes
Deprecations
~~~~~~~~~~~~

-
- :meth:`Index.set_values` has been deprecated. For a given index ``idx``, array ``arr``,
value in ``idx`` of ``idx_val`` and a new value of ``val``, ``idx.set_value(arr, idx_val, val)``
is equivalent to ``arr[idx.get_loc(idx_val) = val``, which should be used instead (:issue:`xxxxx`).
-

.. _whatsnew_1000.prior_deprecations:
Expand Down
8 changes: 8 additions & 0 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4679,10 +4679,18 @@ def set_value(self, arr, key, value):
"""
Fast lookup of value from 1-dimensional ndarray.
.. deprecated:: 1.0
Notes
-----
Only use this if you know what you're doing.
"""
warnings.warn(
("The 'set_value' method is deprecated, and "
"will be removed in a future version."),
FutureWarning,
stacklevel=2,
)
self._engine.set_value(
com.values_from_object(arr), com.values_from_object(key), value
)
Expand Down
12 changes: 8 additions & 4 deletions pandas/tests/indexes/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1908,16 +1908,20 @@ def test_is_monotonic_incomparable(self, attr):
index = Index([5, datetime.now(), 7])
assert not getattr(index, attr)

def test_get_set_value(self):
def test_set_value_deprecated(self):
idx = self.create_index()
arr = np.array([1, 2, 3])
with tm.assert_produces_warning(FutureWarning):
idx.set_value(arr, idx[1], 80)
assert arr[1] == 80

def test_get_value(self):
# TODO: Remove function? GH 19728
values = np.random.randn(100)
date = self.dateIndex[67]

assert_almost_equal(self.dateIndex.get_value(values, date), values[67])

self.dateIndex.set_value(values, date, 10)
assert values[67] == 10

@pytest.mark.parametrize("values", [["foo", "bar", "quux"], {"foo", "bar", "quux"}])
@pytest.mark.parametrize(
"index,expected",
Expand Down

0 comments on commit e775378

Please sign in to comment.