diff --git a/pandas/core/indexes/category.py b/pandas/core/indexes/category.py index ce5cb0779ee53..cdfa07848488b 100644 --- a/pandas/core/indexes/category.py +++ b/pandas/core/indexes/category.py @@ -27,7 +27,6 @@ notna, ) -from pandas.core import accessor from pandas.core.arrays.categorical import ( Categorical, contains, @@ -63,9 +62,8 @@ ], Categorical, ) -@accessor.delegate_names( - delegate=Categorical, - accessors=[ +@inherit_names( + [ "rename_categories", "reorder_categories", "add_categories", @@ -75,10 +73,10 @@ "as_ordered", "as_unordered", ], - typ="method", - overwrite=True, + Categorical, + wrap=True, ) -class CategoricalIndex(NDArrayBackedExtensionIndex, accessor.PandasDelegate): +class CategoricalIndex(NDArrayBackedExtensionIndex): """ Index based on an underlying :class:`Categorical`. @@ -567,13 +565,3 @@ def _concat(self, to_concat: list[Index], name: Hashable) -> Index: else: cat = self._data._from_backing_data(codes) return type(self)._simple_new(cat, name=name) - - def _delegate_method(self, name: str, *args, **kwargs): - """method delegation to the ._values""" - method = getattr(self._values, name) - if "inplace" in kwargs: - raise ValueError("cannot use inplace with CategoricalIndex") - res = method(*args, **kwargs) - if is_scalar(res): - return res - return CategoricalIndex(res, name=self.name) diff --git a/pandas/core/indexes/extension.py b/pandas/core/indexes/extension.py index 6ff20f7d009bc..c522e942c658e 100644 --- a/pandas/core/indexes/extension.py +++ b/pandas/core/indexes/extension.py @@ -102,6 +102,8 @@ def fset(self, value): else: def method(self, *args, **kwargs): + if "inplace" in kwargs: + raise ValueError(f"cannot use inplace with {type(self).__name__}") result = attr(self._data, *args, **kwargs) if wrap: if isinstance(result, type(self._data)):