@@ -14,6 +14,7 @@ from os import PathLike
1414from re import Pattern
1515import sys
1616from typing import (
17+ TYPE_CHECKING ,
1718 Any ,
1819 Generic ,
1920 Literal ,
@@ -25,7 +26,6 @@ from typing import (
2526 overload ,
2627)
2728
28- from _typeshed import _T_contra
2929import numpy as np
3030from numpy import typing as npt
3131import pandas as pd
@@ -87,13 +87,15 @@ HashableT5 = TypeVar("HashableT5", bound=Hashable)
8787
8888ArrayLike : TypeAlias = ExtensionArray | npt .NDArray [Any ]
8989AnyArrayLike : TypeAlias = ArrayLike | Index | Series
90- AnyArrayLikeInt : TypeAlias = (
91- IntegerArray | Index [int ] | Series [int ] | npt .NDArray [np .integer ]
92- )
90+ if TYPE_CHECKING : # noqa: PYI002
91+ AnyArrayLikeInt : TypeAlias = (
92+ IntegerArray | Index [int ] | Series [int ] | npt .NDArray [np .integer ]
93+ )
9394
9495# list-like
9596
9697_T_co = TypeVar ("_T_co" , covariant = True )
98+ _T_contra = TypeVar ("_T_contra" , contravariant = True )
9799
98100class SequenceNotStr (Protocol [_T_co ]):
99101 @overload
@@ -966,8 +968,9 @@ class SupportsDType(Protocol[GenericT_co]):
966968# Similar to npt.DTypeLike but leaves out np.dtype and None for use in overloads
967969DTypeLike : TypeAlias = type [Any ] | tuple [Any , Any ] | list [Any ] | str
968970
969- IndexType : TypeAlias = slice | np_ndarray_anyint | Index | list [int ] | Series [int ]
970- MaskType : TypeAlias = Series [bool ] | np_ndarray_bool | list [bool ]
971+ if TYPE_CHECKING : # noqa: PYI002
972+ IndexType : TypeAlias = slice | np_ndarray_anyint | Index | list [int ] | Series [int ]
973+ MaskType : TypeAlias = Series [bool ] | np_ndarray_bool | list [bool ]
971974
972975# Scratch types for generics
973976
@@ -1039,48 +1042,49 @@ Function: TypeAlias = np.ufunc | Callable[..., Any]
10391042# shared HashableT and HashableT#. This one can be used if the identical
10401043# type is need in a function that uses GroupByObjectNonScalar
10411044_HashableTa = TypeVar ("_HashableTa" , bound = Hashable )
1042- ByT = TypeVar (
1043- "ByT" ,
1044- bound = str
1045- | bytes
1046- | datetime .date
1047- | datetime .datetime
1048- | datetime .timedelta
1049- | np .datetime64
1050- | np .timedelta64
1051- | bool
1052- | int
1053- | float
1054- | complex
1055- | Scalar
1056- | Period
1057- | Interval [int | float | Timestamp | Timedelta ]
1058- | tuple ,
1059- )
1060- # Use a distinct SeriesByT when using groupby with Series of known dtype.
1061- # Essentially, an intersection between Series S1 TypeVar, and ByT TypeVar
1062- SeriesByT = TypeVar (
1063- "SeriesByT" ,
1064- bound = str
1065- | bytes
1066- | datetime .date
1067- | bool
1068- | int
1069- | float
1070- | complex
1071- | datetime .datetime
1072- | datetime .timedelta
1073- | Period
1074- | Interval [int | float | Timestamp | Timedelta ],
1075- )
1045+ if TYPE_CHECKING : # noqa: PYI002
1046+ ByT = TypeVar (
1047+ "ByT" ,
1048+ bound = str
1049+ | bytes
1050+ | datetime .date
1051+ | datetime .datetime
1052+ | datetime .timedelta
1053+ | np .datetime64
1054+ | np .timedelta64
1055+ | bool
1056+ | int
1057+ | float
1058+ | complex
1059+ | Scalar
1060+ | Period
1061+ | Interval [int | float | Timestamp | Timedelta ]
1062+ | tuple ,
1063+ )
1064+ # Use a distinct SeriesByT when using groupby with Series of known dtype.
1065+ # Essentially, an intersection between Series S1 TypeVar, and ByT TypeVar
1066+ SeriesByT = TypeVar (
1067+ "SeriesByT" ,
1068+ bound = str
1069+ | bytes
1070+ | datetime .date
1071+ | bool
1072+ | int
1073+ | float
1074+ | complex
1075+ | datetime .datetime
1076+ | datetime .timedelta
1077+ | Period
1078+ | Interval [int | float | Timestamp | Timedelta ],
1079+ )
10761080GroupByObjectNonScalar : TypeAlias = (
10771081 tuple
10781082 | list [_HashableTa ]
10791083 | Function
10801084 | list [Function ]
10811085 | list [Series ]
1082- | np . ndarray
1083- | list [np . ndarray ]
1086+ | np_ndarray
1087+ | list [np_ndarray ]
10841088 | Mapping [Label , Any ]
10851089 | list [Mapping [Label , Any ]]
10861090 | list [Index ]
0 commit comments