Skip to content

Commit 409ca56

Browse files
GH1398 Remove cast from Index(..., dtype='categorical').array (#1414)
* GH1398 Remove cast from Index(..., dtype='categorical').array * GH1398 Remove cast from Index(..., dtype='categorical').array * GH1398 Remove cast from Index(..., dtype='categorical').array * GH1398 Remove cast from Index(..., dtype='categorical').array * GH1398 Remove cast from Index(..., dtype='categorical').array * GH1398 PR Feedback
1 parent 8823cee commit 409ca56

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

pandas-stubs/core/indexes/category.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ from typing import final
66

77
import numpy as np
88
from pandas.core import accessor
9+
from pandas.core.arrays.categorical import Categorical
910
from pandas.core.indexes.base import Index
1011
from pandas.core.indexes.extension import ExtensionIndex
1112
from typing_extensions import Self
@@ -18,6 +19,8 @@ from pandas._typing import (
1819
class CategoricalIndex(ExtensionIndex[S1], accessor.PandasDelegate):
1920
codes: np.ndarray = ...
2021
categories: Index = ...
22+
@property
23+
def array(self) -> Categorical: ... # type: ignore[override] # pyrefly: ignore[bad-override]
2124
def __new__(
2225
cls,
2326
data: Iterable[S1] = ...,

tests/indexes/test_indexes.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,10 +1531,7 @@ def test_array_property() -> None:
15311531
"""Test that Index.array and semantic Index.array return ExtensionArray and its subclasses"""
15321532
# casting due to pandas-dev/pandas-stubs#1383
15331533
check(
1534-
assert_type(
1535-
cast("Index[pd.CategoricalDtype]", Index([1], dtype="category")).array,
1536-
pd.Categorical,
1537-
),
1534+
assert_type(Index([1], dtype="category").array, pd.Categorical),
15381535
pd.Categorical,
15391536
int,
15401537
)

0 commit comments

Comments
 (0)