Skip to content

Commit a2b9b86

Browse files
committed
pyright happiness
1 parent b9e0b61 commit a2b9b86

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

pandas-stubs/core/algorithms.pyi

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ from pandas.api.extensions import ExtensionArray
1010
from pandas.core.arrays.categorical import Categorical
1111
from pandas.core.indexes.base import Index
1212
from pandas.core.indexes.category import CategoricalIndex
13+
from pandas.core.indexes.datetimes import DatetimeIndex
1314
from pandas.core.indexes.interval import IntervalIndex
1415
from pandas.core.indexes.period import PeriodIndex
16+
from pandas.core.indexes.timedeltas import TimedeltaIndex
1517
from pandas.core.series import Series
1618

1719
from pandas._typing import (
@@ -37,7 +39,11 @@ def unique(
3739
@overload
3840
def unique(values: IntervalIndex[IntervalT]) -> IntervalIndex[IntervalT]: ...
3941
@overload
40-
def unique(values: Index[S1, np_1darray, GenericT_co]) -> np_1darray[GenericT_co]: ...
42+
def unique(values: DatetimeIndex) -> DatetimeIndex | np_1darray[np.datetime64]: ...
43+
@overload
44+
def unique(values: TimedeltaIndex) -> TimedeltaIndex | np_1darray[np.timedelta64]: ...
45+
@overload
46+
def unique(values: Index[S1, Any, GenericT_co]) -> np_1darray[GenericT_co]: ...
4147
@overload
4248
def unique(values: Categorical) -> Categorical: ...
4349
@overload

pandas-stubs/core/indexes/accessors.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ from datetime import (
55
tzinfo as _tzinfo,
66
)
77
from typing import (
8+
Any,
89
Generic,
910
Literal,
1011
TypeVar,
@@ -486,5 +487,5 @@ class ArrayDescriptor:
486487
) -> TimedeltaArray: ...
487488
@overload
488489
def __get__(
489-
self, instance: IndexOpsMixin[int, Never], owner: type[IndexOpsMixin]
490+
self, instance: IndexOpsMixin[Any, Never], owner: type[IndexOpsMixin]
490491
) -> NumpyExtensionArray: ...

tests/test_pandas.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ def test_unique() -> None:
609609
]
610610
)
611611
),
612-
np_1darray[np.datetime64],
612+
pd.DatetimeIndex | np_1darray[np.datetime64],
613613
),
614614
pd.DatetimeIndex,
615615
)
@@ -663,9 +663,9 @@ def test_unique() -> None:
663663
check(
664664
assert_type(
665665
pd.unique(pd.timedelta_range(start="1 day", periods=4)),
666-
np_1darray[np.timedelta64],
666+
pd.TimedeltaIndex | np_1darray[np.timedelta64],
667667
),
668-
np_1darray if PD_LTE_23 else pd.Index,
668+
np_1darray if PD_LTE_23 else pd.TimedeltaIndex,
669669
np.timedelta64 if PD_LTE_23 else pd.Timedelta,
670670
)
671671

@@ -987,8 +987,8 @@ def test_index_unqiue() -> None:
987987

988988
check(assert_type(pd.unique(ci), "pd.CategoricalIndex[str]"), pd.CategoricalIndex)
989989
check(
990-
assert_type(pd.unique(dti), np_1darray[np.datetime64]),
991-
np.ndarray if PD_LTE_23 else pd.Index,
990+
assert_type(pd.unique(dti), pd.DatetimeIndex | np_1darray[np.datetime64]),
991+
np.ndarray if PD_LTE_23 else pd.DatetimeIndex,
992992
np.datetime64 if PD_LTE_23 else pd.Timestamp,
993993
)
994994
check(assert_type(pd.unique(i), np_1darray), np.ndarray if PD_LTE_23 else pd.Index)
@@ -998,8 +998,9 @@ def test_index_unqiue() -> None:
998998
np.ndarray if PD_LTE_23 else pd.Index,
999999
)
10001000
check(
1001-
assert_type(pd.unique(tdi), np_1darray[np.timedelta64]),
1002-
np.ndarray if PD_LTE_23 else pd.Index,
1001+
assert_type(pd.unique(tdi), pd.TimedeltaIndex | np_1darray[np.timedelta64]),
1002+
np_1darray if PD_LTE_23 else pd.TimedeltaIndex,
1003+
np.timedelta64 if PD_LTE_23 else pd.Timedelta,
10031004
)
10041005
check(assert_type(pd.unique(mi), np_1darray), np.ndarray if PD_LTE_23 else pd.Index)
10051006
check(

0 commit comments

Comments
 (0)