Skip to content

TYP: Distinguish use of numpy.dtype and ExtensionDtype #43393

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

Closed
twoertwein opened this issue Sep 3, 2021 · 1 comment
Closed

TYP: Distinguish use of numpy.dtype and ExtensionDtype #43393

twoertwein opened this issue Sep 3, 2021 · 1 comment
Labels
Typing type annotations, mypy/pyright type checking

Comments

@twoertwein
Copy link
Member

Index inherits from IndexOpsMixin which defines self.dtype as a property of Union[np.dtype, "ExtensionDtype"]. There are a few places where either numpy.dtype or ExtensionDtype are expected, but not both:

pandas/core/indexes/base.py:6857: error: Item "dtype[Any]" of "Union[dtype[Any], ExtensionDtype]" has no attribute "categories" [union-attr]
pandas/core/indexes/base.py:6857: error: Item "ExtensionDtype" of "Union[dtype[Any], ExtensionDtype]" has no attribute "categories" [union-attr]
pandas/core/arrays/categorical.py:2649: error: Item "dtype[Any]" of "Union[dtype[Any], ExtensionDtype]" has no attribute "construct_array_type" [union-attr]
pandas/core/indexes/period.py:429: error: Item "dtype[Any]" of "Union[dtype[Any], ExtensionDtype]" has no attribute "resolution" [union-attr]
pandas/core/indexes/period.py:429: error: Item "ExtensionDtype" of "Union[dtype[Any], ExtensionDtype]" has no attribute "resolution" [union-attr]
pandas/core/indexes/period.py:482: error: Item "dtype[Any]" of "Union[dtype[Any], ExtensionDtype]" has no attribute "resolution" [union-attr]
pandas/core/indexes/period.py:482: error: Item "ExtensionDtype" of "Union[dtype[Any], ExtensionDtype]" has no attribute "resolution" [union-attr]
pandas/core/indexes/interval.py:531: error: Item "dtype[Any]" of "Union[dtype[Any], ExtensionDtype]" has no attribute "subtype" [union-attr]
pandas/core/indexes/interval.py:531: error: Item "ExtensionDtype" of "Union[dtype[Any], ExtensionDtype]" has no attribute "subtype" [union-attr]
pandas/core/indexes/interval.py:747: error: Item "dtype[Any]" of "Union[dtype[Any], ExtensionDtype]" has no attribute "subtype" [union-attr]
pandas/core/indexes/interval.py:747: error: Item "ExtensionDtype" of "Union[dtype[Any], ExtensionDtype]" has no attribute "subtype" [union-attr]
pandas/core/internals/blocks.py:1613: error: Item "dtype[Any]" of "Union[dtype[Any], ExtensionDtype]" has no attribute "na_value" [union-attr]

@twoertwein twoertwein added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 3, 2021
@simonjayhawkins simonjayhawkins added Typing type annotations, mypy/pyright type checking and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 4, 2021
@simonjayhawkins simonjayhawkins added this to the Contributions Welcome milestone Sep 4, 2021
@twoertwein
Copy link
Member Author

All of the above cases will need ignore statements. In python 3.10, a few ignore statements can be avoided by using typing.TypeGuard.

I'm closing this issue as ignore statements can only be added once the "CI mypy" starts complaining, which will happen when cache_readonly is typed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Typing type annotations, mypy/pyright type checking
Projects
None yet
Development

No branches or pull requests

2 participants