Skip to content

Commit 67eec4e

Browse files
authored
CLN: Remove older deprecations (#27121)
* Remove Series in rename_categories as list-like * Remove reindex_axis and rename_axis behavior * Add Series.reindex_axis * Fix whatsnew and import error
1 parent b640530 commit 67eec4e

File tree

11 files changed

+13
-210
lines changed

11 files changed

+13
-210
lines changed

doc/source/reference/frame.rst

-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ Reindexing / selection / label manipulation
198198
DataFrame.idxmin
199199
DataFrame.last
200200
DataFrame.reindex
201-
DataFrame.reindex_axis
202201
DataFrame.reindex_like
203202
DataFrame.rename
204203
DataFrame.rename_axis

doc/source/whatsnew/v0.25.0.rst

+3
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,9 @@ Removal of prior version deprecations/changes
627627
- Removed the previously deprecated ``pd.options.html.border`` (:issue:`16970`)
628628
- Removed the previously deprecated ``convert_objects`` (:issue:`11221`)
629629
- Removed the previously deprecated ``select`` method of ``DataFrame`` and ``Series`` (:issue:`17633`)
630+
- Removed the previously deprecated behavior of :class:`Series` treated as list-like in :meth:`~Series.cat.rename_categories` (:issue:`17982`)
631+
- Removed the previously deprecated ``DataFrame.reindex_axis`` and ``Series.reindex_axis``` (:issue:`17842`)
632+
- Removed the previously deprecated behavior of altering column or index labels with :meth:`Series.rename_axis` or :meth:`DataFrame.rename_axis` (:issue:`17842`)
630633

631634
.. _whatsnew_0250.performance:
632635

pandas/core/arrays/categorical.py

-14
Original file line numberDiff line numberDiff line change
@@ -887,11 +887,6 @@ def rename_categories(self, new_categories, inplace=False):
887887
888888
.. versionadded:: 0.23.0
889889
890-
.. warning::
891-
892-
Currently, Series are considered list like. In a future version
893-
of pandas they'll be considered dict-like.
894-
895890
inplace : bool, default False
896891
Whether or not to rename the categories inplace or return a copy of
897892
this categorical with renamed categories.
@@ -939,15 +934,6 @@ def rename_categories(self, new_categories, inplace=False):
939934
inplace = validate_bool_kwarg(inplace, 'inplace')
940935
cat = self if inplace else self.copy()
941936

942-
if isinstance(new_categories, ABCSeries):
943-
msg = ("Treating Series 'new_categories' as a list-like and using "
944-
"the values. In a future version, 'rename_categories' will "
945-
"treat Series like a dictionary.\n"
946-
"For dict-like, use 'new_categories.to_dict()'\n"
947-
"For list-like, use 'new_categories.values'.")
948-
warn(msg, FutureWarning, stacklevel=2)
949-
new_categories = list(new_categories)
950-
951937
if is_dict_like(new_categories):
952938
cat.categories = [new_categories.get(item, item)
953939
for item in cat.categories]

pandas/core/frame.py

-7
Original file line numberDiff line numberDiff line change
@@ -3768,13 +3768,6 @@ def reindex(self, *args, **kwargs):
37683768
kwargs.pop('labels', None)
37693769
return super().reindex(**kwargs)
37703770

3771-
@Appender(_shared_docs['reindex_axis'] % _shared_doc_kwargs)
3772-
def reindex_axis(self, labels, axis=0, method=None, level=None, copy=True,
3773-
limit=None, fill_value=np.nan):
3774-
return super().reindex_axis(labels=labels, axis=axis, method=method,
3775-
level=level, copy=copy, limit=limit,
3776-
fill_value=fill_value)
3777-
37783771
def drop(self, labels=None, axis=0, index=None, columns=None,
37793772
level=None, inplace=False, errors='raise'):
37803773
"""

pandas/core/generic.py

+3-98
Original file line numberDiff line numberDiff line change
@@ -1176,11 +1176,6 @@ def rename_axis(self, mapper=sentinel, **kwargs):
11761176
11771177
Notes
11781178
-----
1179-
Prior to version 0.21.0, ``rename_axis`` could also be used to change
1180-
the axis *labels* by passing a mapping or scalar. This behavior is
1181-
deprecated and will be removed in a future version. Use ``rename``
1182-
instead.
1183-
11841179
``DataFrame.rename_axis`` supports two calling conventions
11851180
11861181
* ``(index=index_mapper, columns=columns_mapper, ...)``
@@ -1280,22 +1275,15 @@ class name
12801275

12811276
inplace = validate_bool_kwarg(inplace, 'inplace')
12821277

1283-
if (mapper is not sentinel):
1278+
if mapper is not sentinel:
12841279
# Use v0.23 behavior if a scalar or list
12851280
non_mapper = is_scalar(mapper) or (is_list_like(mapper) and not
12861281
is_dict_like(mapper))
12871282
if non_mapper:
12881283
return self._set_axis_name(mapper, axis=axis, inplace=inplace)
12891284
else:
1290-
# Deprecated (v0.21) behavior is if mapper is specified,
1291-
# and not a list or scalar, then call rename
1292-
msg = ("Using 'rename_axis' to alter labels is deprecated. "
1293-
"Use '.rename' instead")
1294-
warnings.warn(msg, FutureWarning, stacklevel=3)
1295-
axis = self._get_axis_name(axis)
1296-
d = {'copy': copy, 'inplace': inplace}
1297-
d[axis] = mapper
1298-
return self.rename(**d)
1285+
raise ValueError("Use `.rename` to alter labels "
1286+
"with a mapper.")
12991287
else:
13001288
# Use new behavior. Means that index and/or columns
13011289
# is specified
@@ -4378,89 +4366,6 @@ def _needs_reindex_multi(self, axes, method, level):
43784366
def _reindex_multi(self, axes, copy, fill_value):
43794367
return NotImplemented
43804368

4381-
_shared_docs['reindex_axis'] = ("""
4382-
Conform input object to new index.
4383-
4384-
.. deprecated:: 0.21.0
4385-
Use `reindex` instead.
4386-
4387-
By default, places NaN in locations having no value in the
4388-
previous index. A new object is produced unless the new index
4389-
is equivalent to the current one and copy=False.
4390-
4391-
Parameters
4392-
----------
4393-
labels : array-like
4394-
New labels / index to conform to. Preferably an Index object to
4395-
avoid duplicating data.
4396-
axis : %(axes_single_arg)s
4397-
Indicate whether to use rows or columns.
4398-
method : {None, 'backfill'/'bfill', 'pad'/'ffill', 'nearest'}, optional
4399-
Method to use for filling holes in reindexed DataFrame:
4400-
4401-
* default: don't fill gaps.
4402-
* pad / ffill: propagate last valid observation forward to next
4403-
valid.
4404-
* backfill / bfill: use next valid observation to fill gap.
4405-
* nearest: use nearest valid observations to fill gap.
4406-
4407-
level : int or str
4408-
Broadcast across a level, matching Index values on the
4409-
passed MultiIndex level.
4410-
copy : bool, default True
4411-
Return a new object, even if the passed indexes are the same.
4412-
limit : int, optional
4413-
Maximum number of consecutive elements to forward or backward fill.
4414-
fill_value : float, default NaN
4415-
Value used to fill in locations having no value in the previous
4416-
index.
4417-
4418-
.. versionadded:: 0.21.0 (list-like tolerance)
4419-
4420-
Returns
4421-
-------
4422-
%(klass)s
4423-
Returns a new DataFrame object with new indices, unless the new
4424-
index is equivalent to the current one and copy=False.
4425-
4426-
See Also
4427-
--------
4428-
DataFrame.set_index : Set row labels.
4429-
DataFrame.reset_index : Remove row labels or move them to new columns.
4430-
DataFrame.reindex : Change to new indices or expand indices.
4431-
DataFrame.reindex_like : Change to same indices as other DataFrame.
4432-
4433-
Examples
4434-
--------
4435-
>>> df = pd.DataFrame({'num_legs': [4, 2], 'num_wings': [0, 2]},
4436-
... index=['dog', 'hawk'])
4437-
>>> df
4438-
num_legs num_wings
4439-
dog 4 0
4440-
hawk 2 2
4441-
>>> df.reindex(['num_wings', 'num_legs', 'num_heads'],
4442-
... axis='columns')
4443-
num_wings num_legs num_heads
4444-
dog 0 4 NaN
4445-
hawk 2 2 NaN
4446-
""")
4447-
4448-
@Appender(_shared_docs['reindex_axis'] % _shared_doc_kwargs)
4449-
def reindex_axis(self, labels, axis=0, method=None, level=None, copy=True,
4450-
limit=None, fill_value=None):
4451-
msg = ("'.reindex_axis' is deprecated and will be removed in a future "
4452-
"version. Use '.reindex' instead.")
4453-
self._consolidate_inplace()
4454-
4455-
axis_name = self._get_axis_name(axis)
4456-
axis_values = self._get_axis(axis_name)
4457-
method = missing.clean_reindex_fill_method(method)
4458-
warnings.warn(msg, FutureWarning, stacklevel=3)
4459-
new_index, indexer = axis_values.reindex(labels, method, level,
4460-
limit=limit)
4461-
return self._reindex_with_indexers({axis: [new_index, indexer]},
4462-
fill_value=fill_value, copy=copy)
4463-
44644369
def _reindex_with_indexers(self, reindexers, fill_value=None, copy=False,
44654370
allow_dups=False):
44664371
"""allow_dups indicates an internal call here """

pandas/core/panel.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import pandas.core.common as com
2020
from pandas.core.frame import DataFrame
21-
from pandas.core.generic import NDFrame, _shared_docs
21+
from pandas.core.generic import NDFrame
2222
from pandas.core.index import (
2323
Index, MultiIndex, _get_objs_combined_axis, ensure_index)
2424
import pandas.core.indexes.base as ibase
@@ -1244,13 +1244,6 @@ def rename(self, items=None, major_axis=None, minor_axis=None, **kwargs):
12441244
return super().rename(items=items, major_axis=major_axis,
12451245
minor_axis=minor_axis, **kwargs)
12461246

1247-
@Appender(_shared_docs['reindex_axis'] % _shared_doc_kwargs)
1248-
def reindex_axis(self, labels, axis=0, method=None, level=None, copy=True,
1249-
limit=None, fill_value=np.nan):
1250-
return super().reindex_axis(labels=labels, axis=axis, method=method,
1251-
level=level, copy=copy, limit=limit,
1252-
fill_value=fill_value)
1253-
12541247
@Substitution(**_shared_doc_kwargs)
12551248
@Appender(NDFrame.transpose.__doc__)
12561249
def transpose(self, *args, **kwargs):

pandas/core/series.py

-21
Original file line numberDiff line numberDiff line change
@@ -3998,27 +3998,6 @@ def shift(self, periods=1, freq=None, axis=0, fill_value=None):
39983998
return super().shift(periods=periods, freq=freq, axis=axis,
39993999
fill_value=fill_value)
40004000

4001-
def reindex_axis(self, labels, axis=0, **kwargs):
4002-
"""
4003-
Conform Series to new index with optional filling logic.
4004-
4005-
.. deprecated:: 0.21.0
4006-
Use ``Series.reindex`` instead.
4007-
4008-
Returns
4009-
-------
4010-
Series
4011-
Reindexed Series.
4012-
"""
4013-
# for compatibility with higher dims
4014-
if axis != 0:
4015-
raise ValueError("cannot reindex series on non-zero axis!")
4016-
msg = ("'.reindex_axis' is deprecated and will be removed in a future "
4017-
"version. Use '.reindex' instead.")
4018-
warnings.warn(msg, FutureWarning, stacklevel=2)
4019-
4020-
return self.reindex(index=labels, **kwargs)
4021-
40224001
def memory_usage(self, index=True, deep=False):
40234002
"""
40244003
Return the memory usage of the Series.

pandas/tests/arrays/categorical/test_api.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,7 @@ def test_rename_categories(self):
9191
def test_rename_categories_series(self):
9292
# https://github.com/pandas-dev/pandas/issues/17981
9393
c = Categorical(['a', 'b'])
94-
xpr = "Treating Series 'new_categories' as a list-like "
95-
with tm.assert_produces_warning(FutureWarning) as rec:
96-
result = c.rename_categories(Series([0, 1]))
97-
98-
assert len(rec) == 1
99-
assert xpr in str(rec[0].message)
94+
result = c.rename_categories(Series([0, 1], index=['a', 'b']))
10095
expected = Categorical([0, 1])
10196
tm.assert_categorical_equal(result, expected)
10297

pandas/tests/frame/test_alter_axes.py

+5-9
Original file line numberDiff line numberDiff line change
@@ -668,24 +668,20 @@ def test_rename_axis_inplace(self, float_frame):
668668
assert no_return is None
669669
tm.assert_frame_equal(result, expected)
670670

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

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

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

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

690686
def test_rename_axis_mapper(self):
691687
# GH 19978

pandas/tests/frame/test_axis_select_reindex.py

-38
Original file line numberDiff line numberDiff line change
@@ -416,17 +416,6 @@ def test_reindex_fill_value(self):
416416
expected[4] = 'foo'
417417
assert_frame_equal(result, expected)
418418

419-
# reindex_axis
420-
with tm.assert_produces_warning(FutureWarning):
421-
result = df.reindex_axis(range(15), fill_value=0., axis=0)
422-
expected = df.reindex(range(15)).fillna(0)
423-
assert_frame_equal(result, expected)
424-
425-
with tm.assert_produces_warning(FutureWarning):
426-
result = df.reindex_axis(range(5), fill_value=0., axis=1)
427-
expected = df.reindex(columns=range(5)).fillna(0)
428-
assert_frame_equal(result, expected)
429-
430419
# other dtypes
431420
df['foo'] = 'foo'
432421
result = df.reindex(range(15), fill_value=0)
@@ -1026,33 +1015,6 @@ def test_reindex_corner(self, int_frame):
10261015
smaller = int_frame.reindex(columns=['A', 'B', 'E'])
10271016
assert smaller['E'].dtype == np.float64
10281017

1029-
def test_reindex_axis(self, float_frame, int_frame):
1030-
cols = ['A', 'B', 'E']
1031-
with tm.assert_produces_warning(FutureWarning) as m:
1032-
reindexed1 = int_frame.reindex_axis(cols, axis=1)
1033-
assert 'reindex' in str(m[0].message)
1034-
reindexed2 = int_frame.reindex(columns=cols)
1035-
assert_frame_equal(reindexed1, reindexed2)
1036-
1037-
rows = int_frame.index[0:5]
1038-
with tm.assert_produces_warning(FutureWarning) as m:
1039-
reindexed1 = int_frame.reindex_axis(rows, axis=0)
1040-
assert 'reindex' in str(m[0].message)
1041-
reindexed2 = int_frame.reindex(index=rows)
1042-
assert_frame_equal(reindexed1, reindexed2)
1043-
1044-
msg = ("No axis named 2 for object type"
1045-
" <class 'pandas.core.frame.DataFrame'>")
1046-
with pytest.raises(ValueError, match=msg):
1047-
int_frame.reindex_axis(rows, axis=2)
1048-
1049-
# no-op case
1050-
cols = float_frame.columns.copy()
1051-
with tm.assert_produces_warning(FutureWarning) as m:
1052-
newFrame = float_frame.reindex_axis(cols, axis=1)
1053-
assert 'reindex' in str(m[0].message)
1054-
assert_frame_equal(newFrame, float_frame)
1055-
10561018
def test_reindex_with_nans(self):
10571019
df = DataFrame([[1, 2], [3, 4], [np.nan, np.nan], [7, 8], [9, 10]],
10581020
columns=['a', 'b'],

pandas/tests/sparse/series/test_series.py

-8
Original file line numberDiff line numberDiff line change
@@ -1516,14 +1516,6 @@ def test_deprecated_numpy_func_call(self):
15161516
raise_on_extra_warnings=False):
15171517
getattr(getattr(self, series), func)()
15181518

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

15281520
@pytest.mark.parametrize(
15291521
'datetime_type', (np.datetime64,

0 commit comments

Comments
 (0)