Closed
Description
Currently, IndexType
contains np_ndarray_int64
(a.k.a. npt.NDArray[np.int64]
). Is that possible to add npt.NDArray[np.uint64]
to IndexType
as well?
To Reproduce
import numpy as np
import numpy.typing as npt
import pandas as pd
df = pd.DataFrame(dict(x=[1, 2, 3]), index=np.array([10, 20, 30], dtype="uint64"))
assert df.index.dtype == np.uint64
def get_NDArray(df: pd.DataFrame, key: npt.NDArray[np.uint64]):
df2 = df.loc[key]
reveal_type(df2)
return df2
- Indicate which type checker you are using (
mypy
orpyright
).
Both.
- Show the error message received from that type checker while checking your example.
In pyright
, the inferred type of df2
is Series[Unkown]
, which is incorrect (should be DataFrame
instead).
In mypy
, it says
error: Invalid index type "ndarray[Any, dtype[unsignedinteger[_64Bit]]]"
for "_LocIndexerFrame"; expected type
"Union[slice, ndarray[Any, dtype[signedinteger[_64Bit]]], Index, List[int],
Series[int], Series[bool], ndarray[Any, dtype[bool_]], List[bool],
List[<nothing>], Tuple[Union[slice, ndarray[Any, dtype[signedinteger[_64Bit]]],
Index, List[int], Series[int], Series[bool], ndarray[Any, dtype[bool_]],
List[bool], List[<nothing>], Hashable], Union[List[<nothing>], slice,
Series[bool], Callable[..., Any]]]]"
Please complete the following information:
- OS: MacOS
- OS Version: 13.0.1 (22A400)
- python version: 3.10.8
- version of type checker: mypy: 0.991, Pylance language server 2023.1.10 (pyright bbf0ae78)
- version of installed
pandas-stubs
: 1.5.2.230105 (build pyhd8ed1ab_2)
Metadata
Metadata
Assignees
Labels
No labels