@@ -5,65 +5,75 @@ from typing import (
55)
66
77import numpy as np
8- from pandas import (
9- Categorical ,
10- CategoricalIndex ,
11- Index ,
12- IntervalIndex ,
13- PeriodIndex ,
14- Series ,
15- )
8+ from numpy import typing as npt
169from pandas .api .extensions import ExtensionArray
10+ from pandas .core .arrays .categorical import Categorical
11+ from pandas .core .indexes .base import Index
12+ from pandas .core .indexes .category import CategoricalIndex
13+ from pandas .core .indexes .datetimes import DatetimeIndex
14+ from pandas .core .indexes .interval import IntervalIndex
15+ from pandas .core .indexes .period import PeriodIndex
16+ from pandas .core .series import Series
1717
1818from pandas ._typing import (
19+ T_EXTENSION_ARRAY ,
1920 AnyArrayLike ,
21+ GenericT ,
2022 IntervalT ,
2123 TakeIndexer ,
2224 np_1darray ,
25+ np_ndarray ,
2326)
2427
2528# These are type: ignored because the Index types overlap due to inheritance but indices
2629# with extension types return the same type while standard type return ndarray
27-
28- @overload
29- def unique ( # pyright: ignore[reportOverlappingOverload]
30- values : PeriodIndex ,
31- ) -> PeriodIndex : ...
3230@overload
33- def unique (values : CategoricalIndex ) -> CategoricalIndex : ... # type: ignore[overload-overlap]
31+ def unique (values : CategoricalIndex ) -> CategoricalIndex : ...
3432@overload
3533def unique (values : IntervalIndex [IntervalT ]) -> IntervalIndex [IntervalT ]: ...
3634@overload
37- def unique (values : Index ) -> np .ndarray : ...
35+ def unique (values : PeriodIndex ) -> PeriodIndex : ...
36+ @overload
37+ def unique (values : DatetimeIndex ) -> np_1darray [np .datetime64 ] | DatetimeIndex : ...
38+ @overload
39+ def unique (values : Index ) -> np_1darray [Any ] | Index : ...
3840@overload
3941def unique (values : Categorical ) -> Categorical : ...
42+
43+ # @overload
44+ # def unique(values: Series[Never]) -> np_1darray[Any] | ExtensionArray: ...
45+ # TODO: DatetimeArray python/mypy#19952
46+ # @overload
47+ # def unique(values: Series[Timestamp]) -> np_1darray[np.datetime64] | ExtensionArray: ...
48+ # @overload
49+ # def unique(values: Series[int]) -> np_1darray[np.integer] | ExtensionArray: ...
4050@overload
41- def unique (values : Series ) -> np . ndarray | ExtensionArray : ...
51+ def unique (values : Series ) -> np_1darray [ Any ] | ExtensionArray : ...
4252@overload
43- def unique (values : np . ndarray ) -> np . ndarray : ...
53+ def unique (values : npt . NDArray [ Any ] ) -> np_1darray [ Any ] : ...
4454@overload
45- def unique (values : ExtensionArray ) -> ExtensionArray : ...
55+ def unique (values : T_EXTENSION_ARRAY ) -> T_EXTENSION_ARRAY : ...
4656@overload
4757def factorize (
48- values : np . ndarray ,
58+ values : np_ndarray [ Any , GenericT ] ,
4959 sort : bool = ...,
5060 use_na_sentinel : bool = ...,
5161 size_hint : int | None = ...,
52- ) -> tuple [np .ndarray , np . ndarray ]: ...
62+ ) -> tuple [np_1darray [ np .int64 ], np_1darray [ GenericT ] ]: ...
5363@overload
5464def factorize (
5565 values : Index | Series ,
5666 sort : bool = ...,
5767 use_na_sentinel : bool = ...,
5868 size_hint : int | None = ...,
59- ) -> tuple [np_1darray , Index ]: ...
69+ ) -> tuple [np_1darray [ np . int64 ] , Index ]: ...
6070@overload
6171def factorize (
6272 values : Categorical ,
6373 sort : bool = ...,
6474 use_na_sentinel : bool = ...,
6575 size_hint : int | None = ...,
66- ) -> tuple [np_1darray , Categorical ]: ...
76+ ) -> tuple [np_1darray [ np . int64 ] , Categorical ]: ...
6777def value_counts (
6878 values : AnyArrayLike | list | tuple ,
6979 sort : bool = True ,
@@ -73,9 +83,9 @@ def value_counts(
7383 dropna : bool = True ,
7484) -> Series : ...
7585def take (
76- arr : np . ndarray | ExtensionArray | Index | Series ,
86+ arr : npt . NDArray [ Any ] | ExtensionArray | Index | Series ,
7787 indices : TakeIndexer ,
7888 axis : Literal [0 , 1 ] = 0 ,
7989 allow_fill : bool = False ,
8090 fill_value : Any = None ,
81- ) -> np_1darray | ExtensionArray : ...
91+ ) -> np_1darray [ Any ] | ExtensionArray : ...
0 commit comments