Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEPR: remove previously-deprecated get_value, set_value #27377

Merged
merged 12 commits into from
Jul 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
-
-

Expand Down
38 changes: 3 additions & 35 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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
Expand All @@ -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])
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down
38 changes: 4 additions & 34 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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.

Expand All @@ -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
Expand All @@ -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.
Expand Down
32 changes: 2 additions & 30 deletions pandas/core/sparse/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -465,31 +463,17 @@ 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:
series = self._get_item_cache(col)

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
Expand All @@ -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]
Expand Down
31 changes: 2 additions & 29 deletions pandas/core/sparse/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions pandas/tests/frame/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
12 changes: 4 additions & 8 deletions pandas/tests/frame/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -702,17 +700,15 @@ 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)

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)
Expand Down
Loading