Skip to content
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

Merged
merged 1 commit into from
Nov 17, 2020

Conversation

simonjayhawkins
Copy link
Member

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

def __getitem__(self, key):
def __getitem__(
self: NDArrayBackedExtensionArrayT, key: Union[int, slice, np.ndarray]
) -> Union[NDArrayBackedExtensionArrayT, Any]:
Copy link
Member Author

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]

@simonjayhawkins simonjayhawkins added ExtensionArray Extending pandas with custom dtypes or arrays. Typing type annotations, mypy/pyright type checking labels Nov 16, 2020
@jreback jreback added this to the 1.2 milestone Nov 17, 2020
@jreback
Copy link
Contributor

jreback commented Nov 17, 2020

lgtm any comments @jbrockmendel @jorisvandenbossche

# type (Any) -> Any
def __getitem__(
self, item: Union[int, slice, np.ndarray]
) -> Union[ExtensionArray, Any]:
Copy link
Member

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?

Copy link
Member Author

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

@jreback jreback merged commit 4f738a4 into pandas-dev:master Nov 17, 2020
@jreback
Copy link
Contributor

jreback commented Nov 17, 2020

thanks @simonjayhawkins

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ExtensionArray Extending pandas with custom dtypes or arrays. Typing type annotations, mypy/pyright type checking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants