diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index eed48f9e46897..7af4795fbc3e8 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -60,7 +60,7 @@ Deprecations Removal of prior version deprecations/changes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - +- Removed the previously deprecated :meth:`Series.get_value`, :meth:`Series.set_value`, :meth:`DataFrame.get_value`, :meth:`DataFrame.set_value` (:issue:`17739`) - - diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 4beaf301988b4..c5b7c958e1b5d 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -382,7 +382,7 @@ def _constructor(self): _constructor_sliced = Series # type: Type[Series] _deprecations = NDFrame._deprecations | frozenset( - ["get_value", "set_value", "from_items"] + ["from_items"] ) # type: FrozenSet[str] _accessors = set() # type: Set[str] @@ -2779,13 +2779,10 @@ def _unpickle_matrix_compat(self, state): # pragma: no cover # ---------------------------------------------------------------------- # Getting and setting elements - def get_value(self, index, col, takeable=False): + def _get_value(self, index, col, takeable: bool = False): """ Quickly retrieve single value at passed column and index. - .. deprecated:: 0.21.0 - Use .at[] or .iat[] accessors instead. - Parameters ---------- index : row label @@ -2796,18 +2793,6 @@ def get_value(self, index, col, takeable=False): ------- scalar """ - - warnings.warn( - "get_value is deprecated and will be removed " - "in a future release. Please use " - ".at[] or .iat[] accessors instead", - FutureWarning, - stacklevel=2, - ) - return self._get_value(index, col, takeable=takeable) - - def _get_value(self, index, col, takeable=False): - if takeable: series = self._iget_item_cache(col) return com.maybe_box_datetimelike(series._values[index]) @@ -2831,15 +2816,10 @@ def _get_value(self, index, col, takeable=False): index = self.index.get_loc(index) return self._get_value(index, col, takeable=True) - _get_value.__doc__ = get_value.__doc__ - - def set_value(self, index, col, value, takeable=False): + def _set_value(self, index, col, value, takeable: bool = False): """ Put single value at passed column and index. - .. deprecated:: 0.21.0 - Use .at[] or .iat[] accessors instead. - Parameters ---------- index : row label @@ -2853,16 +2833,6 @@ def set_value(self, index, col, value, takeable=False): If label pair is contained, will be reference to calling DataFrame, otherwise a new object. """ - warnings.warn( - "set_value is deprecated and will be removed " - "in a future release. Please use " - ".at[] or .iat[] accessors instead", - FutureWarning, - stacklevel=2, - ) - return self._set_value(index, col, value, takeable=takeable) - - def _set_value(self, index, col, value, takeable=False): try: if takeable is True: series = self._iget_item_cache(col) @@ -2883,8 +2853,6 @@ def _set_value(self, index, col, value, takeable=False): return self - _set_value.__doc__ = set_value.__doc__ - def _ixs(self, i: int, axis: int = 0): """ Parameters diff --git a/pandas/core/series.py b/pandas/core/series.py index 98a7b279f70b3..418b3fc8c57d0 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -179,7 +179,7 @@ class Series(base.IndexOpsMixin, generic.NDFrame): _accessors = {"dt", "cat", "str", "sparse"} # tolist is not actually deprecated, just suppressed in the __dir__ _deprecations = generic.NDFrame._deprecations | frozenset( - ["asobject", "reshape", "get_value", "set_value", "valid", "tolist"] + ["asobject", "reshape", "valid", "tolist"] ) # Override cache_readonly bc Series is mutable @@ -1367,13 +1367,10 @@ def repeat(self, repeats, axis=None): new_values = self._values.repeat(repeats) return self._constructor(new_values, index=new_index).__finalize__(self) - def get_value(self, label, takeable=False): + def _get_value(self, label, takeable: bool = False): """ Quickly retrieve single value at passed index label. - .. deprecated:: 0.21.0 - Please use .at[] or .iat[] accessors. - Parameters ---------- label : object @@ -1383,29 +1380,14 @@ def get_value(self, label, takeable=False): ------- scalar value """ - warnings.warn( - "get_value is deprecated and will be removed " - "in a future release. Please use " - ".at[] or .iat[] accessors instead", - FutureWarning, - stacklevel=2, - ) - return self._get_value(label, takeable=takeable) - - def _get_value(self, label, takeable=False): - if takeable is True: + if takeable: return com.maybe_box_datetimelike(self._values[label]) return self.index.get_value(self._values, label) - _get_value.__doc__ = get_value.__doc__ - - def set_value(self, label, value, takeable=False): + def _set_value(self, label, value, takeable: bool = False): """ Quickly set single value at passed label. - .. deprecated:: 0.21.0 - Please use .at[] or .iat[] accessors. - If label is not contained, a new object is created with the label placed at the end of the result index. @@ -1423,16 +1405,6 @@ def set_value(self, label, value, takeable=False): If label is contained, will be reference to calling Series, otherwise a new object. """ - warnings.warn( - "set_value is deprecated and will be removed " - "in a future release. Please use " - ".at[] or .iat[] accessors instead", - FutureWarning, - stacklevel=2, - ) - return self._set_value(label, value, takeable=takeable) - - def _set_value(self, label, value, takeable=False): try: if takeable: self._values[label] = value @@ -1445,8 +1417,6 @@ def _set_value(self, label, value, takeable=False): return self - _set_value.__doc__ = set_value.__doc__ - def reset_index(self, level=None, drop=False, name=None, inplace=False): """ Generate a new DataFrame or Series with the index reset. diff --git a/pandas/core/sparse/frame.py b/pandas/core/sparse/frame.py index 54998eb66e69d..2dbf4807cf144 100644 --- a/pandas/core/sparse/frame.py +++ b/pandas/core/sparse/frame.py @@ -447,12 +447,10 @@ def sp_maker(x, index=None): # always return a SparseArray! return clean - def get_value(self, index, col, takeable=False): + def _get_value(self, index, col, takeable=False): """ Quickly retrieve single value at passed column and index - .. deprecated:: 0.21.0 - Please use .at[] or .iat[] accessors. Parameters @@ -465,16 +463,6 @@ def get_value(self, index, col, takeable=False): ------- value : scalar value """ - warnings.warn( - "get_value is deprecated and will be removed " - "in a future release. Please use " - ".at[] or .iat[] accessors instead", - FutureWarning, - stacklevel=2, - ) - return self._get_value(index, col, takeable=takeable) - - def _get_value(self, index, col, takeable=False): if takeable is True: series = self._iget_item_cache(col) else: @@ -482,14 +470,10 @@ def _get_value(self, index, col, takeable=False): return series._get_value(index, takeable=takeable) - _get_value.__doc__ = get_value.__doc__ - - def set_value(self, index, col, value, takeable=False): + def _set_value(self, index, col, value, takeable=False): """ Put single value at passed column and index - .. deprecated:: 0.21.0 - Please use .at[] or .iat[] accessors. Parameters @@ -509,23 +493,11 @@ def set_value(self, index, col, value, takeable=False): ------- frame : DataFrame """ - warnings.warn( - "set_value is deprecated and will be removed " - "in a future release. Please use " - ".at[] or .iat[] accessors instead", - FutureWarning, - stacklevel=2, - ) - return self._set_value(index, col, value, takeable=takeable) - - def _set_value(self, index, col, value, takeable=False): dense = self.to_dense()._set_value(index, col, value, takeable=takeable) return dense.to_sparse( kind=self._default_kind, fill_value=self._default_fill_value ) - _set_value.__doc__ = set_value.__doc__ - def _slice(self, slobj, axis=0, kind=None): if axis == 0: new_index = self.index[slobj] diff --git a/pandas/core/sparse/series.py b/pandas/core/sparse/series.py index 43f2609f46bd6..f5d39c47150a2 100644 --- a/pandas/core/sparse/series.py +++ b/pandas/core/sparse/series.py @@ -386,12 +386,10 @@ def get(self, label, default=None): else: return default - def get_value(self, label, takeable=False): + def _get_value(self, label, takeable=False): """ Retrieve single value at passed index label - .. deprecated:: 0.21.0 - Please use .at[] or .iat[] accessors. Parameters @@ -403,23 +401,10 @@ def get_value(self, label, takeable=False): ------- value : scalar value """ - warnings.warn( - "get_value is deprecated and will be removed " - "in a future release. Please use " - ".at[] or .iat[] accessors instead", - FutureWarning, - stacklevel=2, - ) - - return self._get_value(label, takeable=takeable) - - def _get_value(self, label, takeable=False): loc = label if takeable is True else self.index.get_loc(label) return self._get_val_at(loc) - _get_value.__doc__ = get_value.__doc__ - - def set_value(self, label, value, takeable=False): + def _set_value(self, label, value, takeable=False): """ Quickly set single value at passed label. If label is not contained, a new object is created with the label placed at the end of the result @@ -446,16 +431,6 @@ def set_value(self, label, value, takeable=False): ------- series : SparseSeries """ - warnings.warn( - "set_value is deprecated and will be removed " - "in a future release. Please use " - ".at[] or .iat[] accessors instead", - FutureWarning, - stacklevel=2, - ) - return self._set_value(label, value, takeable=takeable) - - def _set_value(self, label, value, takeable=False): values = self.to_dense() # if the label doesn't exist, we will create a new object here @@ -468,8 +443,6 @@ def _set_value(self, label, value, takeable=False): self._data = SingleBlockManager(values, new_index) self._index = new_index - _set_value.__doc__ = set_value.__doc__ - def _set_values(self, key, value): # this might be inefficient as we have to recreate the sparse array diff --git a/pandas/tests/frame/test_api.py b/pandas/tests/frame/test_api.py index b4b081cfe8d76..c6852576f660b 100644 --- a/pandas/tests/frame/test_api.py +++ b/pandas/tests/frame/test_api.py @@ -67,8 +67,7 @@ def test_getitem_pop_assign_name(self, float_frame): def test_get_value(self, float_frame): for idx in float_frame.index: for col in float_frame.columns: - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - result = float_frame.get_value(idx, col) + result = float_frame._get_value(idx, col) expected = float_frame[col][idx] tm.assert_almost_equal(result, expected) diff --git a/pandas/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py index 29e46ac70c943..ebffeeaa3063e 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -329,10 +329,8 @@ def test_constructor_dict(self): # Dict with None value frame_none = DataFrame(dict(a=None), index=[0]) frame_none_list = DataFrame(dict(a=[None]), index=[0]) - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - assert frame_none.get_value(0, "a") is None - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - assert frame_none_list.get_value(0, "a") is None + assert frame_none._get_value(0, "a") is None + assert frame_none_list._get_value(0, "a") is None tm.assert_frame_equal(frame_none, frame_none_list) # GH10856 @@ -702,8 +700,7 @@ def test_nested_dict_frame_constructor(self): data = {} for col in df.columns: for row in df.index: - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - data.setdefault(col, {})[row] = df.get_value(row, col) + data.setdefault(col, {})[row] = df._get_value(row, col) result = DataFrame(data, columns=rng) tm.assert_frame_equal(result, df) @@ -711,8 +708,7 @@ def test_nested_dict_frame_constructor(self): data = {} for col in df.columns: for row in df.index: - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - data.setdefault(row, {})[col] = df.get_value(row, col) + data.setdefault(row, {})[col] = df._get_value(row, col) result = DataFrame(data, index=rng).T tm.assert_frame_equal(result, df) diff --git a/pandas/tests/frame/test_indexing.py b/pandas/tests/frame/test_indexing.py index 0cb7db0e47123..0fb32dbfcd42d 100644 --- a/pandas/tests/frame/test_indexing.py +++ b/pandas/tests/frame/test_indexing.py @@ -1849,8 +1849,7 @@ def test_getitem_list_duplicates(self): def test_get_value(self, float_frame): for idx in float_frame.index: for col in float_frame.columns: - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - result = float_frame.get_value(idx, col) + result = float_frame._get_value(idx, col) expected = float_frame[col][idx] assert result == expected @@ -1905,42 +1904,34 @@ def test_lookup_raises(self, float_frame): def test_set_value(self, float_frame): for idx in float_frame.index: for col in float_frame.columns: - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - float_frame.set_value(idx, col, 1) + float_frame._set_value(idx, col, 1) assert float_frame[col][idx] == 1 def test_set_value_resize(self, float_frame): - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - res = float_frame.set_value("foobar", "B", 0) + res = float_frame._set_value("foobar", "B", 0) assert res is float_frame assert res.index[-1] == "foobar" - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - assert res.get_value("foobar", "B") == 0 + assert res._get_value("foobar", "B") == 0 float_frame.loc["foobar", "qux"] = 0 - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - assert float_frame.get_value("foobar", "qux") == 0 + assert float_frame._get_value("foobar", "qux") == 0 res = float_frame.copy() - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - res3 = res.set_value("foobar", "baz", "sam") + res3 = res._set_value("foobar", "baz", "sam") assert res3["baz"].dtype == np.object_ res = float_frame.copy() - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - res3 = res.set_value("foobar", "baz", True) + res3 = res._set_value("foobar", "baz", True) assert res3["baz"].dtype == np.object_ res = float_frame.copy() - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - res3 = res.set_value("foobar", "baz", 5) + res3 = res._set_value("foobar", "baz", 5) assert is_float_dtype(res3["baz"]) assert isna(res3["baz"].drop(["foobar"])).all() - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - msg = "could not convert string to float: 'sam'" - with pytest.raises(ValueError, match=msg): - res3.set_value("foobar", "baz", "sam") + msg = "could not convert string to float: 'sam'" + with pytest.raises(ValueError, match=msg): + res3._set_value("foobar", "baz", "sam") def test_set_value_with_index_dtype_change(self): df_orig = DataFrame(np.random.randn(3, 3), index=range(3), columns=list("ABC")) @@ -1948,8 +1939,7 @@ def test_set_value_with_index_dtype_change(self): # this is actually ambiguous as the 2 is interpreted as a positional # so column is not created df = df_orig.copy() - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - df.set_value("C", 2, 1.0) + df._set_value("C", 2, 1.0) assert list(df.index) == list(df_orig.index) + ["C"] # assert list(df.columns) == list(df_orig.columns) + [2] @@ -1960,8 +1950,7 @@ def test_set_value_with_index_dtype_change(self): # create both new df = df_orig.copy() - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - df.set_value("C", "D", 1.0) + df._set_value("C", "D", 1.0) assert list(df.index) == list(df_orig.index) + ["C"] assert list(df.columns) == list(df_orig.columns) + ["D"] @@ -1974,9 +1963,8 @@ def test_get_set_value_no_partial_indexing(self): # partial w/ MultiIndex raise exception index = MultiIndex.from_tuples([(0, 1), (0, 2), (1, 1), (1, 2)]) df = DataFrame(index=index, columns=range(4)) - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - with pytest.raises(KeyError, match=r"^0$"): - df.get_value(0, 1) + with pytest.raises(KeyError, match=r"^0$"): + df._get_value(0, 1) def test_single_element_ix_dont_upcast(self, float_frame): float_frame["E"] = 1 diff --git a/pandas/tests/series/indexing/test_datetime.py b/pandas/tests/series/indexing/test_datetime.py index e0b84e8708fa1..bf8d34cd62ff2 100644 --- a/pandas/tests/series/indexing/test_datetime.py +++ b/pandas/tests/series/indexing/test_datetime.py @@ -110,17 +110,16 @@ def test_series_set_value(): dates = [datetime(2001, 1, 1), datetime(2001, 1, 2)] index = DatetimeIndex(dates) - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - s = Series().set_value(dates[0], 1.0) - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - s2 = s.set_value(dates[1], np.nan) + s = Series()._set_value(dates[0], 1.0) + s2 = s._set_value(dates[1], np.nan) - exp = Series([1.0, np.nan], index=index) + expected = Series([1.0, np.nan], index=index) - assert_series_equal(s2, exp) + assert_series_equal(s2, expected) + # FIXME: dont leave commented-out # s = Series(index[:1], index[:1]) - # s2 = s.set_value(dates[1], index[1]) + # s2 = s._set_value(dates[1], index[1]) # assert s2.values.dtype == 'M8[ns]' diff --git a/pandas/tests/series/indexing/test_indexing.py b/pandas/tests/series/indexing/test_indexing.py index 2d36bfdb93a17..f50b3ddbce7dc 100644 --- a/pandas/tests/series/indexing/test_indexing.py +++ b/pandas/tests/series/indexing/test_indexing.py @@ -372,15 +372,13 @@ def test_setitem_dtypes(): def test_set_value(test_data): idx = test_data.ts.index[10] - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - res = test_data.ts.set_value(idx, 0) + res = test_data.ts._set_value(idx, 0) assert res is test_data.ts assert test_data.ts[idx] == 0 # equiv s = test_data.series.copy() - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - res = s.set_value("foobar", 0) + res = s._set_value("foobar", 0) assert res is s assert res.index[-1] == "foobar" assert res["foobar"] == 0 diff --git a/pandas/tests/sparse/frame/test_frame.py b/pandas/tests/sparse/frame/test_frame.py index 5682c74a8b692..ddb50e0897a86 100644 --- a/pandas/tests/sparse/frame/test_frame.py +++ b/pandas/tests/sparse/frame/test_frame.py @@ -538,28 +538,23 @@ def test_set_value(self, float_frame): # ok, as the index gets converted to object frame = float_frame.copy() - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - res = frame.set_value("foobar", "B", 1.5) + res = frame._set_value("foobar", "B", 1.5) assert res.index.dtype == "object" res = float_frame res.index = res.index.astype(object) - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - res = float_frame.set_value("foobar", "B", 1.5) + res = float_frame._set_value("foobar", "B", 1.5) assert res is not float_frame assert res.index[-1] == "foobar" - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - assert res.get_value("foobar", "B") == 1.5 + assert res._get_value("foobar", "B") == 1.5 - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - res2 = res.set_value("foobar", "qux", 1.5) + res2 = res._set_value("foobar", "qux", 1.5) assert res2 is not res tm.assert_index_equal( res2.columns, pd.Index(list(float_frame.columns) + ["qux"]) ) - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - assert res2.get_value("foobar", "qux") == 1.5 + assert res2._get_value("foobar", "qux") == 1.5 def test_fancy_index_misc(self, float_frame): # axis = 0 diff --git a/pandas/tests/sparse/series/test_series.py b/pandas/tests/sparse/series/test_series.py index a9c3d157dd69b..046e7745fd4ec 100644 --- a/pandas/tests/sparse/series/test_series.py +++ b/pandas/tests/sparse/series/test_series.py @@ -470,18 +470,15 @@ def test_get_get_value(self): expected = self.btseries.to_dense()[dt] tm.assert_almost_equal(result, expected) - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - tm.assert_almost_equal(self.bseries.get_value(10), self.bseries[10]) + tm.assert_almost_equal(self.bseries._get_value(10), self.bseries[10]) def test_set_value(self): idx = self.btseries.index[7] - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - self.btseries.set_value(idx, 0) + self.btseries._set_value(idx, 0) assert self.btseries[idx] == 0 - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - self.iseries.set_value("foobar", 0) + self.iseries._set_value("foobar", 0) assert self.iseries.index[-1] == "foobar" assert self.iseries["foobar"] == 0