Skip to content

Commit d7c2a84

Browse files
authored
REF: use only inherit_names in CategoricalIndex (pandas-dev#42100)
1 parent 960de3a commit d7c2a84

File tree

2 files changed

+7
-17
lines changed

2 files changed

+7
-17
lines changed

pandas/core/indexes/category.py

+5-17
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
notna,
2828
)
2929

30-
from pandas.core import accessor
3130
from pandas.core.arrays.categorical import (
3231
Categorical,
3332
contains,
@@ -63,9 +62,8 @@
6362
],
6463
Categorical,
6564
)
66-
@accessor.delegate_names(
67-
delegate=Categorical,
68-
accessors=[
65+
@inherit_names(
66+
[
6967
"rename_categories",
7068
"reorder_categories",
7169
"add_categories",
@@ -75,10 +73,10 @@
7573
"as_ordered",
7674
"as_unordered",
7775
],
78-
typ="method",
79-
overwrite=True,
76+
Categorical,
77+
wrap=True,
8078
)
81-
class CategoricalIndex(NDArrayBackedExtensionIndex, accessor.PandasDelegate):
79+
class CategoricalIndex(NDArrayBackedExtensionIndex):
8280
"""
8381
Index based on an underlying :class:`Categorical`.
8482
@@ -562,13 +560,3 @@ def _concat(self, to_concat: list[Index], name: Hashable) -> Index:
562560
else:
563561
cat = self._data._from_backing_data(codes)
564562
return type(self)._simple_new(cat, name=name)
565-
566-
def _delegate_method(self, name: str, *args, **kwargs):
567-
"""method delegation to the ._values"""
568-
method = getattr(self._values, name)
569-
if "inplace" in kwargs:
570-
raise ValueError("cannot use inplace with CategoricalIndex")
571-
res = method(*args, **kwargs)
572-
if is_scalar(res):
573-
return res
574-
return CategoricalIndex(res, name=self.name)

pandas/core/indexes/extension.py

+2
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ def fset(self, value):
102102
else:
103103

104104
def method(self, *args, **kwargs):
105+
if "inplace" in kwargs:
106+
raise ValueError(f"cannot use inplace with {type(self).__name__}")
105107
result = attr(self._data, *args, **kwargs)
106108
if wrap:
107109
if isinstance(result, type(self._data)):

0 commit comments

Comments
 (0)