Skip to content

is_numeric_dtype not considering Index as a valid type #415

Closed
@williamjamir

Description

@williamjamir

Describe the bug
As stated in the docs, the is_numeric_dtype function accepts Dtypes, Arrays, and Index as well.
https://pandas.pydata.org/docs/reference/api/pandas.api.types.is_numeric_dtype.html?highlight=example

However, the typings are only contemplating _ArrayOrDtype

def is_numeric_dtype(arr_or_dtype: _ArrayOrDtype) -> bool: ...

To Reproduce

  1. Provide a minimal runnable pandas example that is not properly checked by the stubs.
from pandas.core.dtypes.common import is_numeric_dtype

is_numeric_dtype(pd.Index([1, 2.0]))
>>> mypy --version 
mypy 0.982 (compiled: yes)

Show the error message received from that type checker while checking your example.
(I put one type per line to make the output more readable)

>>> mypy test.py     
/tmp/test.py:4: error: Argument 1 to "is_numeric_dtype" has incompatible type "Index"; 
expected 
"
Union[
    Union[ExtensionArray, ndarray[Any, Any]],
    Union[
        dtype[Any],
        None,
        Type[Any],
        _SupportsDType[dtype[Any]],
        str,
        Union[
            Tuple[Any, int],
            Tuple[Any, Union[SupportsIndex, Sequence[SupportsIndex]]],
            List[Any],
            _DTypeDict,
            Tuple[Any, Any],
        ],
    ],
    Series[Any],
    DataFrame,
]

"  [arg-type]
Found 1 error in 1 file (checked 1 source file)

Please complete the following information:
OS: MacOS M1
OS Version Ventura 13.0
python version: 3.9.12
version of type checker: mypy 0.982 (compiled: yes)
version of installed pandas-stubs
pandas==1.5.1
pandas-stubs==1.5.1.221024

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions