diff --git a/pandas-stubs/core/indexes/category.pyi b/pandas-stubs/core/indexes/category.pyi index 22475842b..a691b7edf 100644 --- a/pandas-stubs/core/indexes/category.pyi +++ b/pandas-stubs/core/indexes/category.pyi @@ -6,6 +6,7 @@ from typing import final import numpy as np from pandas.core import accessor +from pandas.core.arrays.categorical import Categorical from pandas.core.indexes.base import Index from pandas.core.indexes.extension import ExtensionIndex from typing_extensions import Self @@ -18,6 +19,8 @@ from pandas._typing import ( class CategoricalIndex(ExtensionIndex[S1], accessor.PandasDelegate): codes: np.ndarray = ... categories: Index = ... + @property + def array(self) -> Categorical: ... # type: ignore[override] # pyrefly: ignore[bad-override] def __new__( cls, data: Iterable[S1] = ..., diff --git a/tests/indexes/test_indexes.py b/tests/indexes/test_indexes.py index 892cea004..c47947de8 100644 --- a/tests/indexes/test_indexes.py +++ b/tests/indexes/test_indexes.py @@ -1531,10 +1531,7 @@ def test_array_property() -> None: """Test that Index.array and semantic Index.array return ExtensionArray and its subclasses""" # casting due to pandas-dev/pandas-stubs#1383 check( - assert_type( - cast("Index[pd.CategoricalDtype]", Index([1], dtype="category")).array, - pd.Categorical, - ), + assert_type(Index([1], dtype="category").array, pd.Categorical), pd.Categorical, int, )