Skip to content

Remove numpy references from pandas._typing #29064

Closed
@WillAyd

Description

@WillAyd

Because we don't have type information from numpy AND because we specifically ignore_missing_imports for that in our setup, any numpy types currently resolve to Any. This may cause surprising behavior if not scrutinized...

To illustrate, we currently define DType in pandas._typing as Dtype = Union[str, np.dtype, "ExtensionDtype"]. The numpy item here basically makes this a Union[..., Any] so it will almost never fail static analysis. If you remove the np reference therein you will get errors like the following:

pandas/tests/arrays/sparse/test_dtype.py:74: error: Argument 1 to "SparseDtype" has incompatible type "Type[int]"; expected "Union[str, ExtensionDtype]"

In this particular case we probably want to replace np.dtype with Type[Union[float, bool, int, str, object]] to account for legitimate dtype=object calls (@angelaambroz this was mentioned in #29046).

The appearances in TypeVar items may not be as big of a deal, so open to thoughts on whomever wants to review this

@simonjayhawkins

Metadata

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