-
-
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
Conversation
def __getitem__(self, key): | ||
def __getitem__( | ||
self: NDArrayBackedExtensionArrayT, key: Union[int, slice, np.ndarray] | ||
) -> Union[NDArrayBackedExtensionArrayT, Any]: |
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
pandas\core\arrays\datetimelike.py:280: error: Item "NDArrayBackedExtensionArray" of "Union[NDArrayBackedExtensionArray, Any]" has no attribute "_freq" [union-attr]
lgtm any comments @jbrockmendel @jorisvandenbossche |
# 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 comment
The 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 comment
The 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
thanks @simonjayhawkins |
as a precursor to #35259 (comment)
there are more changes/additions needed but this PR might get too big to review and push through in a timely manor.
overload is required to avoid casts
Any is used for any type, whereas should use object.
only the abstract classes have been typed.
could create a scalar type alias in each of the EA classes similar to DTScalarOrNaT in DatetimeLikeArrayMixin
import and expose pandas._libs.missing.NAType in pandas._typing
any of these could be done here or as follow-on