Skip to content

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

Closed
@twoertwein

Description

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]

Metadata

Assignees

No one assigned

    Labels

    Typingtype annotations, mypy/pyright type checking

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions