Skip to content

CLN: Remove older deprecations #27121

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

Merged
merged 4 commits into from
Jun 29, 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
1 change: 0 additions & 1 deletion doc/source/reference/frame.rst
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ Reindexing / selection / label manipulation
DataFrame.idxmin
DataFrame.last
DataFrame.reindex
DataFrame.reindex_axis
DataFrame.reindex_like
DataFrame.rename
DataFrame.rename_axis
Expand Down
3 changes: 3 additions & 0 deletions doc/source/whatsnew/v0.25.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,9 @@ Removal of prior version deprecations/changes
- Removed the previously deprecated ``pd.options.html.border`` (:issue:`16970`)
- Removed the previously deprecated ``convert_objects`` (:issue:`11221`)
- Removed the previously deprecated ``select`` method of ``DataFrame`` and ``Series`` (:issue:`17633`)
- Removed the previously deprecated behavior of :class:`Series` treated as list-like in :meth:`~Series.cat.rename_categories` (:issue:`17982`)
- Removed the previously deprecated ``DataFrame.reindex_axis`` and ``Series.reindex_axis``` (:issue:`17842`)
- Removed the previously deprecated behavior of altering column or index labels with :meth:`Series.rename_axis` or :meth:`DataFrame.rename_axis` (:issue:`17842`)

.. _whatsnew_0250.performance:

Expand Down
14 changes: 0 additions & 14 deletions pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -887,11 +887,6 @@ def rename_categories(self, new_categories, inplace=False):

.. versionadded:: 0.23.0

.. warning::

Currently, Series are considered list like. In a future version
of pandas they'll be considered dict-like.

inplace : bool, default False
Whether or not to rename the categories inplace or return a copy of
this categorical with renamed categories.
Expand Down Expand Up @@ -939,15 +934,6 @@ def rename_categories(self, new_categories, inplace=False):
inplace = validate_bool_kwarg(inplace, 'inplace')
cat = self if inplace else self.copy()

if isinstance(new_categories, ABCSeries):
msg = ("Treating Series 'new_categories' as a list-like and using "
"the values. In a future version, 'rename_categories' will "
"treat Series like a dictionary.\n"
"For dict-like, use 'new_categories.to_dict()'\n"
"For list-like, use 'new_categories.values'.")
warn(msg, FutureWarning, stacklevel=2)
new_categories = list(new_categories)

if is_dict_like(new_categories):
cat.categories = [new_categories.get(item, item)
for item in cat.categories]
Expand Down
7 changes: 0 additions & 7 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3768,13 +3768,6 @@ def reindex(self, *args, **kwargs):
kwargs.pop('labels', None)
return super().reindex(**kwargs)

@Appender(_shared_docs['reindex_axis'] % _shared_doc_kwargs)
def reindex_axis(self, labels, axis=0, method=None, level=None, copy=True,
limit=None, fill_value=np.nan):
return super().reindex_axis(labels=labels, axis=axis, method=method,
level=level, copy=copy, limit=limit,
fill_value=fill_value)

def drop(self, labels=None, axis=0, index=None, columns=None,
level=None, inplace=False, errors='raise'):
"""
Expand Down
101 changes: 3 additions & 98 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1176,11 +1176,6 @@ def rename_axis(self, mapper=sentinel, **kwargs):

Notes
-----
Prior to version 0.21.0, ``rename_axis`` could also be used to change
the axis *labels* by passing a mapping or scalar. This behavior is
deprecated and will be removed in a future version. Use ``rename``
instead.

``DataFrame.rename_axis`` supports two calling conventions

* ``(index=index_mapper, columns=columns_mapper, ...)``
Expand Down Expand Up @@ -1280,22 +1275,15 @@ class name

inplace = validate_bool_kwarg(inplace, 'inplace')

if (mapper is not sentinel):
if mapper is not sentinel:
# Use v0.23 behavior if a scalar or list
non_mapper = is_scalar(mapper) or (is_list_like(mapper) and not
is_dict_like(mapper))
if non_mapper:
return self._set_axis_name(mapper, axis=axis, inplace=inplace)
else:
# Deprecated (v0.21) behavior is if mapper is specified,
# and not a list or scalar, then call rename
msg = ("Using 'rename_axis' to alter labels is deprecated. "
"Use '.rename' instead")
warnings.warn(msg, FutureWarning, stacklevel=3)
axis = self._get_axis_name(axis)
d = {'copy': copy, 'inplace': inplace}
d[axis] = mapper
return self.rename(**d)
raise ValueError("Use `.rename` to alter labels "
"with a mapper.")
else:
# Use new behavior. Means that index and/or columns
# is specified
Expand Down Expand Up @@ -4378,89 +4366,6 @@ def _needs_reindex_multi(self, axes, method, level):
def _reindex_multi(self, axes, copy, fill_value):
return NotImplemented

_shared_docs['reindex_axis'] = ("""
Conform input object to new index.

.. deprecated:: 0.21.0
Use `reindex` instead.

By default, places NaN in locations having no value in the
previous index. A new object is produced unless the new index
is equivalent to the current one and copy=False.

Parameters
----------
labels : array-like
New labels / index to conform to. Preferably an Index object to
avoid duplicating data.
axis : %(axes_single_arg)s
Indicate whether to use rows or columns.
method : {None, 'backfill'/'bfill', 'pad'/'ffill', 'nearest'}, optional
Method to use for filling holes in reindexed DataFrame:

* default: don't fill gaps.
* pad / ffill: propagate last valid observation forward to next
valid.
* backfill / bfill: use next valid observation to fill gap.
* nearest: use nearest valid observations to fill gap.

level : int or str
Broadcast across a level, matching Index values on the
passed MultiIndex level.
copy : bool, default True
Return a new object, even if the passed indexes are the same.
limit : int, optional
Maximum number of consecutive elements to forward or backward fill.
fill_value : float, default NaN
Value used to fill in locations having no value in the previous
index.

.. versionadded:: 0.21.0 (list-like tolerance)

Returns
-------
%(klass)s
Returns a new DataFrame object with new indices, unless the new
index is equivalent to the current one and copy=False.

See Also
--------
DataFrame.set_index : Set row labels.
DataFrame.reset_index : Remove row labels or move them to new columns.
DataFrame.reindex : Change to new indices or expand indices.
DataFrame.reindex_like : Change to same indices as other DataFrame.

Examples
--------
>>> df = pd.DataFrame({'num_legs': [4, 2], 'num_wings': [0, 2]},
... index=['dog', 'hawk'])
>>> df
num_legs num_wings
dog 4 0
hawk 2 2
>>> df.reindex(['num_wings', 'num_legs', 'num_heads'],
... axis='columns')
num_wings num_legs num_heads
dog 0 4 NaN
hawk 2 2 NaN
""")

@Appender(_shared_docs['reindex_axis'] % _shared_doc_kwargs)
def reindex_axis(self, labels, axis=0, method=None, level=None, copy=True,
limit=None, fill_value=None):
msg = ("'.reindex_axis' is deprecated and will be removed in a future "
"version. Use '.reindex' instead.")
self._consolidate_inplace()

axis_name = self._get_axis_name(axis)
axis_values = self._get_axis(axis_name)
method = missing.clean_reindex_fill_method(method)
warnings.warn(msg, FutureWarning, stacklevel=3)
new_index, indexer = axis_values.reindex(labels, method, level,
limit=limit)
return self._reindex_with_indexers({axis: [new_index, indexer]},
fill_value=fill_value, copy=copy)

def _reindex_with_indexers(self, reindexers, fill_value=None, copy=False,
allow_dups=False):
"""allow_dups indicates an internal call here """
Expand Down
9 changes: 1 addition & 8 deletions pandas/core/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import pandas.core.common as com
from pandas.core.frame import DataFrame
from pandas.core.generic import NDFrame, _shared_docs
from pandas.core.generic import NDFrame
from pandas.core.index import (
Index, MultiIndex, _get_objs_combined_axis, ensure_index)
import pandas.core.indexes.base as ibase
Expand Down Expand Up @@ -1244,13 +1244,6 @@ def rename(self, items=None, major_axis=None, minor_axis=None, **kwargs):
return super().rename(items=items, major_axis=major_axis,
minor_axis=minor_axis, **kwargs)

@Appender(_shared_docs['reindex_axis'] % _shared_doc_kwargs)
def reindex_axis(self, labels, axis=0, method=None, level=None, copy=True,
limit=None, fill_value=np.nan):
return super().reindex_axis(labels=labels, axis=axis, method=method,
level=level, copy=copy, limit=limit,
fill_value=fill_value)

@Substitution(**_shared_doc_kwargs)
@Appender(NDFrame.transpose.__doc__)
def transpose(self, *args, **kwargs):
Expand Down
21 changes: 0 additions & 21 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -3998,27 +3998,6 @@ def shift(self, periods=1, freq=None, axis=0, fill_value=None):
return super().shift(periods=periods, freq=freq, axis=axis,
fill_value=fill_value)

def reindex_axis(self, labels, axis=0, **kwargs):
"""
Conform Series to new index with optional filling logic.

.. deprecated:: 0.21.0
Use ``Series.reindex`` instead.

Returns
-------
Series
Reindexed Series.
"""
# for compatibility with higher dims
if axis != 0:
raise ValueError("cannot reindex series on non-zero axis!")
msg = ("'.reindex_axis' is deprecated and will be removed in a future "
"version. Use '.reindex' instead.")
warnings.warn(msg, FutureWarning, stacklevel=2)

return self.reindex(index=labels, **kwargs)

def memory_usage(self, index=True, deep=False):
"""
Return the memory usage of the Series.
Expand Down
7 changes: 1 addition & 6 deletions pandas/tests/arrays/categorical/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,7 @@ def test_rename_categories(self):
def test_rename_categories_series(self):
# https://github.com/pandas-dev/pandas/issues/17981
c = Categorical(['a', 'b'])
xpr = "Treating Series 'new_categories' as a list-like "
with tm.assert_produces_warning(FutureWarning) as rec:
result = c.rename_categories(Series([0, 1]))

assert len(rec) == 1
assert xpr in str(rec[0].message)
result = c.rename_categories(Series([0, 1], index=['a', 'b']))
expected = Categorical([0, 1])
tm.assert_categorical_equal(result, expected)

Expand Down
14 changes: 5 additions & 9 deletions pandas/tests/frame/test_alter_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,24 +668,20 @@ def test_rename_axis_inplace(self, float_frame):
assert no_return is None
tm.assert_frame_equal(result, expected)

def test_rename_axis_warns(self):
def test_rename_axis_raises(self):
# https://github.com/pandas-dev/pandas/issues/17833
df = DataFrame({"A": [1, 2], "B": [1, 2]})
with tm.assert_produces_warning(FutureWarning) as w:
with pytest.raises(ValueError, match="Use `.rename`"):
df.rename_axis(id, axis=0)
assert 'rename' in str(w[0].message)

with tm.assert_produces_warning(FutureWarning) as w:
with pytest.raises(ValueError, match="Use `.rename`"):
df.rename_axis({0: 10, 1: 20}, axis=0)
assert 'rename' in str(w[0].message)

with tm.assert_produces_warning(FutureWarning) as w:
with pytest.raises(ValueError, match="Use `.rename`"):
df.rename_axis(id, axis=1)
assert 'rename' in str(w[0].message)

with tm.assert_produces_warning(FutureWarning) as w:
with pytest.raises(ValueError, match="Use `.rename`"):
df['A'].rename_axis(id)
assert 'rename' in str(w[0].message)

def test_rename_axis_mapper(self):
# GH 19978
Expand Down
38 changes: 0 additions & 38 deletions pandas/tests/frame/test_axis_select_reindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,17 +416,6 @@ def test_reindex_fill_value(self):
expected[4] = 'foo'
assert_frame_equal(result, expected)

# reindex_axis
with tm.assert_produces_warning(FutureWarning):
result = df.reindex_axis(range(15), fill_value=0., axis=0)
expected = df.reindex(range(15)).fillna(0)
assert_frame_equal(result, expected)

with tm.assert_produces_warning(FutureWarning):
result = df.reindex_axis(range(5), fill_value=0., axis=1)
expected = df.reindex(columns=range(5)).fillna(0)
assert_frame_equal(result, expected)

# other dtypes
df['foo'] = 'foo'
result = df.reindex(range(15), fill_value=0)
Expand Down Expand Up @@ -1026,33 +1015,6 @@ def test_reindex_corner(self, int_frame):
smaller = int_frame.reindex(columns=['A', 'B', 'E'])
assert smaller['E'].dtype == np.float64

def test_reindex_axis(self, float_frame, int_frame):
cols = ['A', 'B', 'E']
with tm.assert_produces_warning(FutureWarning) as m:
reindexed1 = int_frame.reindex_axis(cols, axis=1)
assert 'reindex' in str(m[0].message)
reindexed2 = int_frame.reindex(columns=cols)
assert_frame_equal(reindexed1, reindexed2)

rows = int_frame.index[0:5]
with tm.assert_produces_warning(FutureWarning) as m:
reindexed1 = int_frame.reindex_axis(rows, axis=0)
assert 'reindex' in str(m[0].message)
reindexed2 = int_frame.reindex(index=rows)
assert_frame_equal(reindexed1, reindexed2)

msg = ("No axis named 2 for object type"
" <class 'pandas.core.frame.DataFrame'>")
with pytest.raises(ValueError, match=msg):
int_frame.reindex_axis(rows, axis=2)

# no-op case
cols = float_frame.columns.copy()
with tm.assert_produces_warning(FutureWarning) as m:
newFrame = float_frame.reindex_axis(cols, axis=1)
assert 'reindex' in str(m[0].message)
assert_frame_equal(newFrame, float_frame)

def test_reindex_with_nans(self):
df = DataFrame([[1, 2], [3, 4], [np.nan, np.nan], [7, 8], [9, 10]],
columns=['a', 'b'],
Expand Down
8 changes: 0 additions & 8 deletions pandas/tests/sparse/series/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1516,14 +1516,6 @@ def test_deprecated_numpy_func_call(self):
raise_on_extra_warnings=False):
getattr(getattr(self, series), func)()

def test_deprecated_reindex_axis(self):
# https://github.com/pandas-dev/pandas/issues/17833
# Multiple FutureWarnings, can't check stacklevel
with tm.assert_produces_warning(FutureWarning,
check_stacklevel=False) as m:
self.bseries.reindex_axis([0, 1, 2])
assert 'reindex' in str(m[0].message)


@pytest.mark.parametrize(
'datetime_type', (np.datetime64,
Expand Down