From ec7b086f2b17066213812b98ef88b39ab96ac2b1 Mon Sep 17 00:00:00 2001 From: Jeff Reback Date: Mon, 2 Oct 2017 07:43:30 -0400 Subject: [PATCH] DEPR: deprecate .get_value and .set_value for Series, DataFrame, Panel, SparseSeries, SparseDataFrame closes #15269 --- doc/source/whatsnew/v0.21.0.txt | 3 +- pandas/core/frame.py | 34 ++++++++++++++-- pandas/core/indexing.py | 10 ++--- pandas/core/panel.py | 30 ++++++++++++-- pandas/core/series.py | 30 ++++++++++++-- pandas/core/sparse/frame.py | 44 ++++++++++++++++++-- pandas/core/sparse/series.py | 29 +++++++++++++- pandas/tests/frame/test_api.py | 4 +- pandas/tests/frame/test_constructors.py | 16 ++++++-- pandas/tests/frame/test_indexing.py | 53 ++++++++++++++++++------- pandas/tests/series/test_indexing.py | 16 ++++++-- pandas/tests/sparse/test_frame.py | 20 +++++++--- pandas/tests/sparse/test_series.py | 13 ++++-- pandas/tests/test_panel.py | 25 +++++++----- 14 files changed, 264 insertions(+), 63 deletions(-) diff --git a/doc/source/whatsnew/v0.21.0.txt b/doc/source/whatsnew/v0.21.0.txt index d7789bfbfd04c..66b44d4d391e1 100644 --- a/doc/source/whatsnew/v0.21.0.txt +++ b/doc/source/whatsnew/v0.21.0.txt @@ -666,7 +666,8 @@ Deprecations - ``pd.TimeGrouper`` is deprecated in favor of :class:`pandas.Grouper` (:issue:`16747`) - ``cdate_range`` has been deprecated in favor of :func:`bdate_range`, which has gained ``weekmask`` and ``holidays`` parameters for building custom frequency date ranges. See the :ref:`documentation ` for more details (:issue:`17596`) - passing ``categories`` or ``ordered`` kwargs to :func:`Series.astype` is deprecated, in favor of passing a :ref:`CategoricalDtype ` (:issue:`17636`) -- Passing a non-existant column in ``.to_excel(..., columns=)`` is deprecated and will raise a ``KeyError`` in the future (:issue:`17295`) +- Passing a non-existent column in ``.to_excel(..., columns=)`` is deprecated and will raise a ``KeyError`` in the future (:issue:`17295`) +- ``.get_value`` and ``.set_value`` on ``Series``, ``DataFrame``, ``Panel``, ``SparseSeries``, and ``SparseDataFrame`` are deprecated in favor of using ``.iat[]`` or ``.at[]`` accessors (:issue:`15269`) .. _whatsnew_0210.deprecations.select: diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 778a3dc9046a3..a77c002b625cb 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -297,7 +297,8 @@ def _constructor(self): return DataFrame _constructor_sliced = Series - _deprecations = NDFrame._deprecations | frozenset(['sortlevel']) + _deprecations = NDFrame._deprecations | frozenset( + ['sortlevel', 'get_value', 'set_value']) @property def _constructor_expanddim(self): @@ -1922,6 +1923,10 @@ 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 ---------- index : row label @@ -1933,6 +1938,14 @@ 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: series = self._iget_item_cache(col) return _maybe_box_datetimelike(series._values[index]) @@ -1948,12 +1961,17 @@ def get_value(self, index, col, takeable=False): # use positional col = self.columns.get_loc(col) index = self.index.get_loc(index) - return self.get_value(index, col, takeable=True) + return self._get_value(index, col, takeable=True) + _get_value.__doc__ = get_value.__doc__ 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 ---------- index : row label @@ -1967,10 +1985,17 @@ 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) - return series.set_value(index, value, takeable=True) + return series._set_value(index, value, takeable=True) series = self._get_item_cache(col) engine = self.index._engine @@ -1983,6 +2008,7 @@ def set_value(self, index, col, value, takeable=False): self._item_cache.pop(col, None) return self + _set_value.__doc__ = set_value.__doc__ def _ixs(self, i, axis=0): """ @@ -2791,7 +2817,7 @@ def lookup(self, row_labels, col_labels): else: result = np.empty(n, dtype='O') for i, (r, c) in enumerate(zip(row_labels, col_labels)): - result[i] = self.get_value(r, c) + result[i] = self._get_value(r, c) if is_object_dtype(result): result = lib.maybe_convert_objects(result) diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index 199aa9cfca506..f1a3fe81a4540 100755 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -112,7 +112,7 @@ def __getitem__(self, key): key = tuple(com._apply_if_callable(x, self.obj) for x in key) try: - values = self.obj.get_value(*key) + values = self.obj._get_value(*key) if is_scalar(values): return values except Exception: @@ -1542,7 +1542,7 @@ def _is_scalar_access(self, key): def _getitem_scalar(self, key): # a fast-path to scalar access # if not, raise - values = self.obj.get_value(*key) + values = self.obj._get_value(*key) return values def _get_partial_string_timestamp_match_key(self, key, labels): @@ -1701,7 +1701,7 @@ def _is_scalar_access(self, key): def _getitem_scalar(self, key): # a fast-path to scalar access # if not, raise - values = self.obj.get_value(*key, takeable=True) + values = self.obj._get_value(*key, takeable=True) return values def _is_valid_integer(self, key, axis): @@ -1866,7 +1866,7 @@ def __getitem__(self, key): raise ValueError('Invalid call for scalar access (getting)!') key = self._convert_key(key) - return self.obj.get_value(*key, takeable=self._takeable) + return self.obj._get_value(*key, takeable=self._takeable) def __setitem__(self, key, value): if isinstance(key, tuple): @@ -1883,7 +1883,7 @@ def __setitem__(self, key, value): '(setting)!') key = list(self._convert_key(key, is_setter=True)) key.append(value) - self.obj.set_value(*key, takeable=self._takeable) + self.obj._set_value(*key, takeable=self._takeable) class _AtIndexer(_ScalarAccessIndexer): diff --git a/pandas/core/panel.py b/pandas/core/panel.py index 68733a3a8b94e..fad6a39223b9e 100644 --- a/pandas/core/panel.py +++ b/pandas/core/panel.py @@ -470,6 +470,10 @@ def get_value(self, *args, **kwargs): """ Quickly retrieve single value at (item, major, minor) location + .. deprecated:: 0.21.0 + + Please use .at[] or .iat[] accessors. + Parameters ---------- item : item label (panel item) @@ -481,6 +485,13 @@ def get_value(self, *args, **kwargs): ------- 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(*args, **kwargs) + + def _get_value(self, *args, **kwargs): nargs = len(args) nreq = self._AXIS_LEN @@ -500,12 +511,17 @@ def get_value(self, *args, **kwargs): else: lower = self._get_item_cache(args[0]) - return lower.get_value(*args[1:], takeable=takeable) + return lower._get_value(*args[1:], takeable=takeable) + _get_value.__doc__ = get_value.__doc__ def set_value(self, *args, **kwargs): """ Quickly set single value at (item, major, minor) location + .. deprecated:: 0.21.0 + + Please use .at[] or .iat[] accessors. + Parameters ---------- item : item label (panel item) @@ -520,6 +536,13 @@ def set_value(self, *args, **kwargs): If label combo is contained, will be reference to calling Panel, 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(*args, **kwargs) + + def _set_value(self, *args, **kwargs): # require an arg for each axis and the value nargs = len(args) nreq = self._AXIS_LEN + 1 @@ -540,7 +563,7 @@ def set_value(self, *args, **kwargs): else: lower = self._get_item_cache(args[0]) - lower.set_value(*args[1:], takeable=takeable) + lower._set_value(*args[1:], takeable=takeable) return self except KeyError: axes = self._expand_axes(args) @@ -553,7 +576,8 @@ def set_value(self, *args, **kwargs): if made_bigger: maybe_cast_item(result, args[0], likely_dtype) - return result.set_value(*args) + return result._set_value(*args) + _set_value.__doc__ = set_value.__doc__ def _box_item_values(self, key, values): if self.ndim == values.ndim: diff --git a/pandas/core/series.py b/pandas/core/series.py index 58cac46f63d7e..43b7f1d043e4d 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -147,7 +147,7 @@ class Series(base.IndexOpsMixin, generic.NDFrame): _metadata = ['name'] _accessors = frozenset(['dt', 'cat', 'str']) _deprecations = generic.NDFrame._deprecations | frozenset( - ['sortlevel', 'reshape']) + ['sortlevel', 'reshape', 'get_value', 'set_value']) _allow_index_ops = True def __init__(self, data=None, index=None, dtype=None, name=None, @@ -902,6 +902,10 @@ def get_value(self, label, takeable=False): """ Quickly retrieve single value at passed index label + .. deprecated:: 0.21.0 + + Please use .at[] or .iat[] accessors. + Parameters ---------- index : label @@ -911,9 +915,17 @@ 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): if takeable is True: return _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): """ @@ -921,6 +933,10 @@ def set_value(self, label, value, takeable=False): new object is created with the label placed at the end of the result index + .. deprecated:: 0.21.0 + + Please use .at[] or .iat[] accessors. + Parameters ---------- label : object @@ -935,17 +951,25 @@ 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 else: self.index._engine.set_value(self._values, label, value) - return self except KeyError: # set using a non-recursive method self.loc[label] = value - return self + + return self + _set_value.__doc__ = set_value.__doc__ def reset_index(self, level=None, drop=False, name=None, inplace=False): """ diff --git a/pandas/core/sparse/frame.py b/pandas/core/sparse/frame.py index 7aa49efa82f61..a43aad9a0204e 100644 --- a/pandas/core/sparse/frame.py +++ b/pandas/core/sparse/frame.py @@ -5,6 +5,7 @@ from __future__ import division # pylint: disable=E1101,E1103,W0231,E0202 +import warnings from pandas.compat import lmap from pandas import compat import numpy as np @@ -430,19 +431,47 @@ def __getitem__(self, key): else: return self._get_item_cache(key) - @Appender(DataFrame.get_value.__doc__, indents=0) 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 + ---------- + index : row label + col : column label + takeable : interpret the index/col as indexers, default False + + Returns + ------- + 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: series = self._get_item_cache(col) - return series.get_value(index, takeable=takeable) + return series._get_value(index, takeable=takeable) + _get_value.__doc__ = get_value.__doc__ 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 ---------- index : row label @@ -460,9 +489,18 @@ def set_value(self, index, col, value, takeable=False): ------- frame : DataFrame """ - dense = self.to_dense().set_value(index, col, value, takeable=takeable) + 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: diff --git a/pandas/core/sparse/series.py b/pandas/core/sparse/series.py index 5166dc927989e..3255bd6bd17e8 100644 --- a/pandas/core/sparse/series.py +++ b/pandas/core/sparse/series.py @@ -426,7 +426,7 @@ def _get_values(self, indexer): return self[indexer] def _set_with_engine(self, key, value): - return self.set_value(key, value) + return self._set_value(key, value) def abs(self): """ @@ -466,6 +466,10 @@ 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 ---------- index : label @@ -475,8 +479,17 @@ 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): """ @@ -484,6 +497,10 @@ def set_value(self, label, value, takeable=False): new object is created with the label placed at the end of the result index + .. deprecated:: 0.21.0 + + Please use .at[] or .iat[] accessors. + Parameters ---------- label : object @@ -501,11 +518,18 @@ 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 # and possibily change the index - new_values = values.set_value(label, value, takeable=takeable) + new_values = values._set_value(label, value, takeable=takeable) if new_values is not None: values = new_values new_index = values.index @@ -513,6 +537,7 @@ def set_value(self, label, value, takeable=False): kind=self.kind) self._data = SingleBlockManager(values, new_index) self._index = new_index + _set_value.__doc__ = set_value.__doc__ def _set_values(self, key, value): diff --git a/pandas/tests/frame/test_api.py b/pandas/tests/frame/test_api.py index 5ea8230ced41b..be6d81c63ae1e 100644 --- a/pandas/tests/frame/test_api.py +++ b/pandas/tests/frame/test_api.py @@ -69,7 +69,9 @@ def test_getitem_pop_assign_name(self): def test_get_value(self): for idx in self.frame.index: for col in self.frame.columns: - result = self.frame.get_value(idx, col) + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + result = self.frame.get_value(idx, col) expected = self.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 d0cd1899a0a3c..7f1cc12ec4277 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -258,8 +258,12 @@ 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]) - assert frame_none.get_value(0, 'a') is None - assert frame_none_list.get_value(0, 'a') is None + 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 tm.assert_frame_equal(frame_none, frame_none_list) # GH10856 @@ -509,7 +513,9 @@ def test_nested_dict_frame_constructor(self): data = {} for col in df.columns: for row in df.index: - data.setdefault(col, {})[row] = df.get_value(row, col) + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + data.setdefault(col, {})[row] = df.get_value(row, col) result = DataFrame(data, columns=rng) tm.assert_frame_equal(result, df) @@ -517,7 +523,9 @@ def test_nested_dict_frame_constructor(self): data = {} for col in df.columns: for row in df.index: - data.setdefault(row, {})[col] = df.get_value(row, col) + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + 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 dd2759cd3ef8e..d00f56830a6fa 100644 --- a/pandas/tests/frame/test_indexing.py +++ b/pandas/tests/frame/test_indexing.py @@ -1629,7 +1629,9 @@ def test_getitem_list_duplicates(self): def test_get_value(self): for idx in self.frame.index: for col in self.frame.columns: - result = self.frame.get_value(idx, col) + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + result = self.frame.get_value(idx, col) expected = self.frame[col][idx] assert result == expected @@ -1637,7 +1639,9 @@ def test_lookup(self): def alt(df, rows, cols, dtype): result = [] for r, c in zip(rows, cols): - result.append(df.get_value(r, c)) + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + result.append(df.get_value(r, c)) return np.array(result, dtype=dtype) def testit(df): @@ -1671,32 +1675,48 @@ def testit(df): def test_set_value(self): for idx in self.frame.index: for col in self.frame.columns: - self.frame.set_value(idx, col, 1) + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + self.frame.set_value(idx, col, 1) assert self.frame[col][idx] == 1 def test_set_value_resize(self): - res = self.frame.set_value('foobar', 'B', 0) + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + res = self.frame.set_value('foobar', 'B', 0) assert res is self.frame assert res.index[-1] == 'foobar' - assert res.get_value('foobar', 'B') == 0 + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + assert res.get_value('foobar', 'B') == 0 self.frame.loc['foobar', 'qux'] = 0 - assert self.frame.get_value('foobar', 'qux') == 0 + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + assert self.frame.get_value('foobar', 'qux') == 0 res = self.frame.copy() - res3 = res.set_value('foobar', 'baz', 'sam') + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + res3 = res.set_value('foobar', 'baz', 'sam') assert res3['baz'].dtype == np.object_ res = self.frame.copy() - res3 = res.set_value('foobar', 'baz', True) + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + res3 = res.set_value('foobar', 'baz', True) assert res3['baz'].dtype == np.object_ res = self.frame.copy() - res3 = res.set_value('foobar', 'baz', 5) + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + res3 = res.set_value('foobar', 'baz', 5) assert is_float_dtype(res3['baz']) assert isna(res3['baz'].drop(['foobar'])).all() - pytest.raises(ValueError, res3.set_value, 'foobar', 'baz', 'sam') + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + pytest.raises(ValueError, res3.set_value, 'foobar', 'baz', 'sam') def test_set_value_with_index_dtype_change(self): df_orig = DataFrame(randn(3, 3), index=lrange(3), columns=list('ABC')) @@ -1704,7 +1724,9 @@ 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() - df.set_value('C', 2, 1.0) + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + 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] @@ -1715,7 +1737,9 @@ def test_set_value_with_index_dtype_change(self): # create both new df = df_orig.copy() - df.set_value('C', 'D', 1.0) + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + 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'] @@ -1728,8 +1752,9 @@ 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=lrange(4)) - pytest.raises(KeyError, df.get_value, 0, 1) - # pytest.raises(KeyError, df.set_value, 0, 1, 0) + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + pytest.raises(KeyError, df.get_value, 0, 1) def test_single_element_ix_dont_upcast(self): self.frame['E'] = 1 diff --git a/pandas/tests/series/test_indexing.py b/pandas/tests/series/test_indexing.py index 93e7b81163b54..0ca319565e24b 100644 --- a/pandas/tests/series/test_indexing.py +++ b/pandas/tests/series/test_indexing.py @@ -800,13 +800,17 @@ def test_setitem_dtypes(self): def test_set_value(self): idx = self.ts.index[10] - res = self.ts.set_value(idx, 0) + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + res = self.ts.set_value(idx, 0) assert res is self.ts assert self.ts[idx] == 0 # equiv s = self.series.copy() - res = s.set_value('foobar', 0) + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + res = s.set_value('foobar', 0) assert res is s assert res.index[-1] == 'foobar' assert res['foobar'] == 0 @@ -2632,8 +2636,12 @@ def test_series_set_value(self): dates = [datetime(2001, 1, 1), datetime(2001, 1, 2)] index = DatetimeIndex(dates) - s = Series().set_value(dates[0], 1.) - s2 = s.set_value(dates[1], np.nan) + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + s = Series().set_value(dates[0], 1.) + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + s2 = s.set_value(dates[1], np.nan) exp = Series([1., np.nan], index=index) diff --git a/pandas/tests/sparse/test_frame.py b/pandas/tests/sparse/test_frame.py index ed4a3a9e5f75f..ef94e2f78278d 100644 --- a/pandas/tests/sparse/test_frame.py +++ b/pandas/tests/sparse/test_frame.py @@ -430,22 +430,32 @@ def test_set_value(self): # ok, as the index gets converted to object frame = self.frame.copy() - res = frame.set_value('foobar', 'B', 1.5) + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + res = frame.set_value('foobar', 'B', 1.5) assert res.index.dtype == 'object' res = self.frame res.index = res.index.astype(object) - res = self.frame.set_value('foobar', 'B', 1.5) + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + res = self.frame.set_value('foobar', 'B', 1.5) assert res is not self.frame assert res.index[-1] == 'foobar' - assert res.get_value('foobar', 'B') == 1.5 + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + assert res.get_value('foobar', 'B') == 1.5 - res2 = res.set_value('foobar', 'qux', 1.5) + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + res2 = res.set_value('foobar', 'qux', 1.5) assert res2 is not res tm.assert_index_equal(res2.columns, pd.Index(list(self.frame.columns) + ['qux'])) - assert res2.get_value('foobar', 'qux') == 1.5 + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + assert res2.get_value('foobar', 'qux') == 1.5 def test_fancy_index_misc(self): # axis = 0 diff --git a/pandas/tests/sparse/test_series.py b/pandas/tests/sparse/test_series.py index 13dab68b2e5b4..7c7399317809f 100644 --- a/pandas/tests/sparse/test_series.py +++ b/pandas/tests/sparse/test_series.py @@ -465,15 +465,22 @@ def test_get_get_value(self): expected = self.btseries.to_dense()[dt] tm.assert_almost_equal(result, expected) - tm.assert_almost_equal(self.bseries.get_value(10), self.bseries[10]) + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + tm.assert_almost_equal( + self.bseries.get_value(10), self.bseries[10]) def test_set_value(self): idx = self.btseries.index[7] - self.btseries.set_value(idx, 0) + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + self.btseries.set_value(idx, 0) assert self.btseries[idx] == 0 - self.iseries.set_value('foobar', 0) + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + self.iseries.set_value('foobar', 0) assert self.iseries.index[-1] == 'foobar' assert self.iseries['foobar'] == 0 diff --git a/pandas/tests/test_panel.py b/pandas/tests/test_panel.py index a6113f231f8f2..c8e056f156218 100644 --- a/pandas/tests/test_panel.py +++ b/pandas/tests/test_panel.py @@ -405,7 +405,9 @@ def test_get_value(self): for item in self.panel.items: for mjr in self.panel.major_axis[::2]: for mnr in self.panel.minor_axis: - result = self.panel.get_value(item, mjr, mnr) + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + result = self.panel.get_value(item, mjr, mnr) expected = self.panel[item][mnr][mjr] assert_almost_equal(result, expected) @@ -867,16 +869,17 @@ def test_comp(func): test_comp(operator.le) def test_get_value(self): - for item in self.panel.items: - for mjr in self.panel.major_axis[::2]: - for mnr in self.panel.minor_axis: - result = self.panel.get_value(item, mjr, mnr) - expected = self.panel[item][mnr][mjr] - assert_almost_equal(result, expected) - with tm.assert_raises_regex(TypeError, - "There must be an argument " - "for each axis"): - self.panel.get_value('a') + with catch_warnings(record=True): + for item in self.panel.items: + for mjr in self.panel.major_axis[::2]: + for mnr in self.panel.minor_axis: + result = self.panel.get_value(item, mjr, mnr) + expected = self.panel[item][mnr][mjr] + assert_almost_equal(result, expected) + with tm.assert_raises_regex(TypeError, + "There must be an argument " + "for each axis"): + self.panel.get_value('a') def test_set_value(self): with catch_warnings(record=True):