Skip to content

Commit 5b1fbcb

Browse files
topper-123Terji Petersen
and
Terji Petersen
authored
DEPR: drop setting categorical codes (#49258)
* DEPR: drop setting categorical codes * add gh-number * add gh-number * fix gh-number Co-authored-by: Terji Petersen <[email protected]>
1 parent ee82f27 commit 5b1fbcb

File tree

3 files changed

+1
-19
lines changed

3 files changed

+1
-19
lines changed

doc/source/whatsnew/v2.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ Removal of prior version deprecations/changes
216216
- Removed ``pandas.SparseArray`` in favor of :class:`arrays.SparseArray` (:issue:`30642`)
217217
- Removed ``pandas.SparseSeries`` and ``pandas.SparseDataFrame`` (:issue:`30642`)
218218
- Enforced disallowing a string column label into ``times`` in :meth:`DataFrame.ewm` (:issue:`43265`)
219+
- Removed setting Categorical._codes directly (:issue:`41429`)
219220
- Enforced :meth:`Rolling.count` with ``min_periods=None`` to default to the size of the window (:issue:`31302`)
220221
- Removed the deprecated method ``mad`` from pandas classes (:issue:`11787`)
221222
- Removed the deprecated method ``tshift`` from pandas classes (:issue:`11631`)

pandas/core/arrays/categorical.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2059,16 +2059,6 @@ def _values_for_rank(self):
20592059
def _codes(self) -> np.ndarray:
20602060
return self._ndarray
20612061

2062-
@_codes.setter
2063-
def _codes(self, value: np.ndarray) -> None:
2064-
warn(
2065-
"Setting the codes on a Categorical is deprecated and will raise in "
2066-
"a future version. Create a new Categorical object instead",
2067-
FutureWarning,
2068-
stacklevel=find_stack_level(),
2069-
) # GH#40606
2070-
NDArrayBacked.__init__(self, value, self.dtype)
2071-
20722062
def _box_func(self, i: int):
20732063
if i == -1:
20742064
return np.NaN

pandas/tests/arrays/categorical/test_api.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -516,15 +516,6 @@ def test_set_categories_inplace(self, factor):
516516

517517
tm.assert_index_equal(cat.categories, Index(["a", "b", "c", "d"]))
518518

519-
def test_codes_setter_deprecated(self):
520-
cat = Categorical([1, 2, 3, 1, 2, 3, 3, 2, 1, 1, 1])
521-
new_codes = cat._codes + 1
522-
with tm.assert_produces_warning(FutureWarning):
523-
# GH#40606
524-
cat._codes = new_codes
525-
526-
assert cat._codes is new_codes
527-
528519

529520
class TestPrivateCategoricalAPI:
530521
def test_codes_immutable(self):

0 commit comments

Comments
 (0)