Skip to content

Commit ea73e0b

Browse files
jbrockmendeljreback
authored andcommitted
DEPR: CategoricalIndex.take_nd (#30702)
1 parent b3caae0 commit ea73e0b

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

doc/source/whatsnew/v1.0.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ Deprecations
568568
- :func:`eval` keyword argument "truediv" is deprecated and will be removed in a future version (:issue:`29812`)
569569
- :meth:`DateOffset.isAnchored` and :meth:`DatetOffset.onOffset` are deprecated and will be removed in a future version, use :meth:`DateOffset.is_anchored` and :meth:`DateOffset.is_on_offset` instead (:issue:`30340`)
570570
- ``pandas.tseries.frequencies.get_offset`` is deprecated and will be removed in a future version, use ``pandas.tseries.frequencies.to_offset`` instead (:issue:`4205`)
571-
- :meth:`Categorical.take_nd` is deprecated, use :meth:`Categorical.take` instead (:issue:`27745`)
571+
- :meth:`Categorical.take_nd` and :meth:`CategoricalIndex.take_nd` are deprecated, use :meth:`Categorical.take` and :meth:`CategoricalIndex.take` instead (:issue:`27745`)
572572
- The parameter ``numeric_only`` of :meth:`Categorical.min` and :meth:`Categorical.max` is deprecated and replaced with ``skipna`` (:issue:`25303`)
573573
- The parameter ``label`` in :func:`lreshape` has been deprecated and will be removed in a future version (:issue:`29742`)
574574
- ``pandas.core.index`` has been deprecated and will be removed in a future version, the public classes are available in the top-level namespace (:issue:`19711`)

pandas/core/indexes/category.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import operator
22
from typing import Any, List
3+
import warnings
34

45
import numpy as np
56

@@ -735,7 +736,13 @@ def take(self, indices, axis=0, allow_fill=True, fill_value=None, **kwargs):
735736
)
736737
return self._shallow_copy(taken)
737738

738-
take_nd = take
739+
def take_nd(self, *args, **kwargs):
740+
warnings.warn(
741+
"CategoricalIndex.take_nd is deprecated, use CategoricalIndex.take instead",
742+
FutureWarning,
743+
stacklevel=2,
744+
)
745+
return self.take(*args, **kwargs)
739746

740747
@Appender(_index_shared_docs["_maybe_cast_slice_bound"])
741748
def _maybe_cast_slice_bound(self, label, side, kind):

pandas/tests/arrays/categorical/test_algos.py

+4
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,7 @@ def test_take_nd_deprecated(self):
177177
cat = pd.Categorical(["a", "b", "c"])
178178
with tm.assert_produces_warning(FutureWarning):
179179
cat.take_nd([0, 1])
180+
181+
ci = pd.Index(cat)
182+
with tm.assert_produces_warning(FutureWarning):
183+
ci.take_nd([0, 1])

0 commit comments

Comments
 (0)