Skip to content

Commit 89b0bc2

Browse files
committed
DEPR: Deprecate Index.set_value
1 parent 83eb75b commit 89b0bc2

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

doc/source/whatsnew/v1.0.0.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ Other API changes
116116
Deprecations
117117
~~~~~~~~~~~~
118118

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

122124
.. _whatsnew_1000.prior_deprecations:

pandas/core/indexes/base.py

+10
Original file line numberDiff line numberDiff line change
@@ -4679,10 +4679,20 @@ def set_value(self, arr, key, value):
46794679
"""
46804680
Fast lookup of value from 1-dimensional ndarray.
46814681
4682+
.. deprecated:: 1.0
4683+
46824684
Notes
46834685
-----
46844686
Only use this if you know what you're doing.
46854687
"""
4688+
warnings.warn(
4689+
(
4690+
"The 'set_value' method is deprecated, and "
4691+
"will be removed in a future version."
4692+
),
4693+
FutureWarning,
4694+
stacklevel=2,
4695+
)
46864696
self._engine.set_value(
46874697
com.values_from_object(arr), com.values_from_object(key), value
46884698
)

pandas/tests/indexes/test_base.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -1908,16 +1908,20 @@ def test_is_monotonic_incomparable(self, attr):
19081908
index = Index([5, datetime.now(), 7])
19091909
assert not getattr(index, attr)
19101910

1911-
def test_get_set_value(self):
1911+
def test_set_value_deprecated(self):
1912+
idx = self.create_index()
1913+
arr = np.array([1, 2, 3])
1914+
with tm.assert_produces_warning(FutureWarning):
1915+
idx.set_value(arr, idx[1], 80)
1916+
assert arr[1] == 80
1917+
1918+
def test_get_value(self):
19121919
# TODO: Remove function? GH 19728
19131920
values = np.random.randn(100)
19141921
date = self.dateIndex[67]
19151922

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

1918-
self.dateIndex.set_value(values, date, 10)
1919-
assert values[67] == 10
1920-
19211925
@pytest.mark.parametrize("values", [["foo", "bar", "quux"], {"foo", "bar", "quux"}])
19221926
@pytest.mark.parametrize(
19231927
"index,expected",

0 commit comments

Comments
 (0)