-
-
Notifications
You must be signed in to change notification settings - Fork 150
GH1398 Remove cast from Index(..., dtype='categorical').array #1414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GH1398 Remove cast from Index(..., dtype='categorical').array #1414
Conversation
There was a problem hiding this 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.
@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] |
There was a problem hiding this comment.
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.
@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] |
There was a problem hiding this 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 !
Index([1], dtype="category").array
givesExtensionArray
instead ofpd.Categorical
#1398assert_type()
to assert the type of any return value