Skip to content

Commit 900ab38

Browse files
committed
Inplace was deprecated in remove_categories.
1 parent 9e52128 commit 900ab38

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

doc/source/whatsnew/v1.2.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ Deprecations
478478
- Partial slicing on unordered :class:`DatetimeIndex` with keys, which are not in Index is deprecated and will be removed in a future version (:issue:`18531`)
479479
- Deprecated :meth:`Index.asi8` for :class:`Index` subclasses other than :class:`DatetimeIndex`, :class:`TimedeltaIndex`, and :class:`PeriodIndex` (:issue:`37877`)
480480
- The ``inplace`` parameter of :meth:`Categorical.remove_unused_categories` is deprecated and will be removed in a future version (:issue:`37643`)
481+
- The ``inplace`` parameter of :meth:`Categorical.remove_categories` is deprecated and will be removed in a future version (:issue:`37643`)
481482

482483
.. ---------------------------------------------------------------------------
483484

pandas/core/arrays/categorical.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,7 @@ def add_categories(self, new_categories, inplace=False):
10161016
if not inplace:
10171017
return cat
10181018

1019-
def remove_categories(self, removals, inplace=False):
1019+
def remove_categories(self, removals, inplace=no_default):
10201020
"""
10211021
Remove the specified categories.
10221022
@@ -1031,6 +1031,8 @@ def remove_categories(self, removals, inplace=False):
10311031
Whether or not to remove the categories inplace or return a copy of
10321032
this categorical with removed categories.
10331033
1034+
.. deprecated:: 1.2.0
1035+
10341036
Returns
10351037
-------
10361038
cat : Categorical or None
@@ -1049,6 +1051,17 @@ def remove_categories(self, removals, inplace=False):
10491051
remove_unused_categories : Remove categories which are not used.
10501052
set_categories : Set the categories to the specified ones.
10511053
"""
1054+
if inplace is not no_default:
1055+
warn(
1056+
"The `inplace` parameter in pandas.Categorical."
1057+
"remove_categories is deprecated and "
1058+
"will be removed in a future version.",
1059+
FutureWarning,
1060+
stacklevel=2,
1061+
)
1062+
else:
1063+
inplace = False
1064+
10521065
inplace = validate_bool_kwarg(inplace, "inplace")
10531066
if not is_list_like(removals):
10541067
removals = [removals]

pandas/tests/arrays/categorical/test_analytics.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,9 @@ def test_validate_inplace_raises(self, value):
352352
cat.add_categories(new_categories=["D", "E", "F"], inplace=value)
353353

354354
with pytest.raises(ValueError, match=msg):
355-
cat.remove_categories(removals=["D", "E", "F"], inplace=value)
355+
with tm.assert_produces_warning(FutureWarning):
356+
# issue #37643 inplace kwarg deprecated
357+
cat.remove_categories(removals=["D", "E", "F"], inplace=value)
356358

357359
with pytest.raises(ValueError, match=msg):
358360
with tm.assert_produces_warning(FutureWarning):

pandas/tests/arrays/categorical/test_api.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,10 @@ def test_remove_categories(self):
348348
tm.assert_categorical_equal(res, new)
349349

350350
# inplace == True
351-
res = cat.remove_categories("c", inplace=True)
351+
with tm.assert_produces_warning(FutureWarning):
352+
# issue #37643 inplace kwarg deprecated
353+
res = cat.remove_categories("c", inplace=True)
354+
352355
tm.assert_categorical_equal(cat, new)
353356
assert res is None
354357

0 commit comments

Comments
 (0)