Skip to content

Conversation

loicdiridollou
Copy link
Member

@loicdiridollou loicdiridollou requested a review from cmp0xff October 9, 2025 01:58
Copy link
Contributor

@cmp0xff cmp0xff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR. It would be great if we could make changes in the existing code, instead of adding a new class.

@loicdiridollou loicdiridollou requested a review from cmp0xff October 9, 2025 12:21
Comment on lines 23 to 30
@type_check_only
class CategoricalArrayDescriptor:
def __get__(self, instance, owner: type[IndexOpsMixin]) -> Categorical: ...

class CategoricalIndex(ExtensionIndex[S1], accessor.PandasDelegate):
codes: np.ndarray = ...
categories: Index = ...
array = CategoricalArrayDescriptor() # pyrefly: ignore[bad-override]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is only one return type, so we can use a static @property instead.

Suggested change
@type_check_only
class CategoricalArrayDescriptor:
def __get__(self, instance, owner: type[IndexOpsMixin]) -> Categorical: ...
class CategoricalIndex(ExtensionIndex[S1], accessor.PandasDelegate):
codes: np.ndarray = ...
categories: Index = ...
array = CategoricalArrayDescriptor() # pyrefly: ignore[bad-override]
class CategoricalIndex(ExtensionIndex[S1], accessor.PandasDelegate):
codes: np.ndarray = ...
categories: Index = ...
@property
def array(self) -> Categorical: ... # pyrefly: ignore[bad-override]

Copy link
Contributor

@cmp0xff cmp0xff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good to me. I assume that you have finished the PR but forgot to click request review. Thank you @loicdiridollou !

@cmp0xff cmp0xff merged commit 409ca56 into pandas-dev:main Oct 10, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Index([1], dtype="category").array gives ExtensionArray instead of pd.Categorical

2 participants