diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 0880b8e2cac12..0d6660b4a27f1 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -198,6 +198,7 @@ Removal of prior version deprecations/changes - Removed ``pandas.SparseArray`` in favor of :class:`arrays.SparseArray` (:issue:`30642`) - Removed ``pandas.SparseSeries`` and ``pandas.SparseDataFrame`` (:issue:`30642`) - Enforced disallowing a string column label into ``times`` in :meth:`DataFrame.ewm` (:issue:`43265`) +- Removed setting Categorical._codes directly (:issue:`41429`) - Enforced :meth:`Rolling.count` with ``min_periods=None`` to default to the size of the window (:issue:`31302`) - diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index 48371b7f14b28..15a7c8d52b724 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -2059,16 +2059,6 @@ def _values_for_rank(self): def _codes(self) -> np.ndarray: return self._ndarray - @_codes.setter - def _codes(self, value: np.ndarray) -> None: - warn( - "Setting the codes on a Categorical is deprecated and will raise in " - "a future version. Create a new Categorical object instead", - FutureWarning, - stacklevel=find_stack_level(), - ) # GH#40606 - NDArrayBacked.__init__(self, value, self.dtype) - def _box_func(self, i: int): if i == -1: return np.NaN diff --git a/pandas/tests/arrays/categorical/test_api.py b/pandas/tests/arrays/categorical/test_api.py index e3fd73aaa9b1c..03bd1c522838d 100644 --- a/pandas/tests/arrays/categorical/test_api.py +++ b/pandas/tests/arrays/categorical/test_api.py @@ -516,15 +516,6 @@ def test_set_categories_inplace(self, factor): tm.assert_index_equal(cat.categories, Index(["a", "b", "c", "d"])) - def test_codes_setter_deprecated(self): - cat = Categorical([1, 2, 3, 1, 2, 3, 3, 2, 1, 1, 1]) - new_codes = cat._codes + 1 - with tm.assert_produces_warning(FutureWarning): - # GH#40606 - cat._codes = new_codes - - assert cat._codes is new_codes - class TestPrivateCategoricalAPI: def test_codes_immutable(self):