Skip to content

DEPR: drop setting categorical codes #49258

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
Oct 24, 2022
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: 1 addition & 0 deletions doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
-

Expand Down
10 changes: 0 additions & 10 deletions pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 0 additions & 9 deletions pandas/tests/arrays/categorical/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down