-
-
Notifications
You must be signed in to change notification settings - Fork 18.3k
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
TYP: __getitem__ method of EA #37898
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ | |
This is an experimental API and subject to breaking changes | ||
without warning. | ||
""" | ||
from __future__ import annotations | ||
|
||
import operator | ||
from typing import ( | ||
Any, | ||
|
@@ -254,8 +256,9 @@ def _from_factorized(cls, values, original): | |
# Must be a Sequence | ||
# ------------------------------------------------------------------------ | ||
|
||
def __getitem__(self, item): | ||
# type (Any) -> Any | ||
def __getitem__( | ||
self, item: Union[int, slice, np.ndarray] | ||
) -> Union[ExtensionArray, Any]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should ExtensionArray be a typevar here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes it should. Until there is consensus on usage have only added where needed to keep mypy green. see #37898 (comment), #37817 (comment), #31728 (comment), #31384 (comment) and others |
||
""" | ||
Select a subset of self. | ||
|
||
|
@@ -661,7 +664,7 @@ def dropna(self): | |
""" | ||
return self[~self.isna()] | ||
|
||
def shift(self, periods: int = 1, fill_value: object = None) -> "ExtensionArray": | ||
def shift(self, periods: int = 1, fill_value: object = None) -> ExtensionArray: | ||
""" | ||
Shift values by desired number. | ||
|
||
|
@@ -831,7 +834,7 @@ def _values_for_factorize(self) -> Tuple[np.ndarray, Any]: | |
""" | ||
return self.astype(object), np.nan | ||
|
||
def factorize(self, na_sentinel: int = -1) -> Tuple[np.ndarray, "ExtensionArray"]: | ||
def factorize(self, na_sentinel: int = -1) -> Tuple[np.ndarray, ExtensionArray]: | ||
""" | ||
Encode the extension array as an enumerated type. | ||
|
||
|
@@ -940,7 +943,7 @@ def take( | |
*, | ||
allow_fill: bool = False, | ||
fill_value: Any = None, | ||
) -> "ExtensionArray": | ||
) -> ExtensionArray: | ||
""" | ||
Take elements from an array. | ||
|
||
|
@@ -1109,7 +1112,7 @@ def _formatter(self, boxed: bool = False) -> Callable[[Any], Optional[str]]: | |
# Reshaping | ||
# ------------------------------------------------------------------------ | ||
|
||
def transpose(self, *axes) -> "ExtensionArray": | ||
def transpose(self, *axes) -> ExtensionArray: | ||
""" | ||
Return a transposed view on this array. | ||
|
||
|
@@ -1119,10 +1122,10 @@ def transpose(self, *axes) -> "ExtensionArray": | |
return self[:] | ||
|
||
@property | ||
def T(self) -> "ExtensionArray": | ||
def T(self) -> ExtensionArray: | ||
return self.transpose() | ||
|
||
def ravel(self, order="C") -> "ExtensionArray": | ||
def ravel(self, order="C") -> ExtensionArray: | ||
""" | ||
Return a flattened view on this array. | ||
|
||
|
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.
cc @jorisvandenbossche if typevar is not used, mypy gives