@@ -76,6 +76,7 @@ from pandas.tseries.offsets import (
7676P = ParamSpec ("P" )
7777
7878HashableT = TypeVar ("HashableT" , bound = Hashable )
79+ HashableT0 = TypeVar ("HashableT0" , bound = Hashable , default = Any )
7980HashableT1 = TypeVar ("HashableT1" , bound = Hashable )
8081HashableT2 = TypeVar ("HashableT2" , bound = Hashable )
8182HashableT3 = TypeVar ("HashableT3" , bound = Hashable )
@@ -774,7 +775,7 @@ XMLParsers: TypeAlias = Literal["lxml", "etree"]
774775HTMLFlavors : TypeAlias = Literal ["lxml" , "html5lib" , "bs4" ]
775776
776777# Interval closed type
777- IntervalT = TypeVar ("IntervalT" , bound = Interval )
778+ IntervalT = TypeVar ("IntervalT" , bound = Interval , default = Interval )
778779IntervalLeftRight : TypeAlias = Literal ["left" , "right" ]
779780IntervalClosedType : TypeAlias = IntervalLeftRight | Literal ["both" , "neither" ]
780781
@@ -872,7 +873,11 @@ ExcelWriterMergeCells: TypeAlias = bool | Literal["columns"]
872873
873874# read_csv: usecols
874875UsecolsArgType : TypeAlias = (
875- SequenceNotStr [Hashable ] | range | AnyArrayLike | Callable [[HashableT ], bool ] | None
876+ SequenceNotStr [Hashable ]
877+ | range
878+ | AnyArrayLike
879+ | Callable [[HashableT0 ], bool ]
880+ | None
876881)
877882
878883# maintain the sub-type of any hashable sequence
@@ -918,6 +923,7 @@ PyArrowNotStrDtypeArg: TypeAlias = (
918923StrLike : TypeAlias = str | np .str_
919924
920925ScalarT = TypeVar ("ScalarT" , bound = Scalar )
926+ ScalarT0 = TypeVar ("ScalarT0" , bound = Scalar , default = Scalar )
921927# Refine the definitions below in 3.9 to use the specialized type.
922928np_num : TypeAlias = np .bool | np .integer | np .floating | np .complexfloating
923929np_ndarray_intp : TypeAlias = npt .NDArray [np .intp ]
@@ -959,7 +965,10 @@ np_1darray_dt: TypeAlias = np_1darray[np.datetime64]
959965np_1darray_td : TypeAlias = np_1darray [np .timedelta64 ]
960966np_2darray : TypeAlias = np .ndarray [tuple [int , int ], np .dtype [GenericT ]]
961967
962- NDArrayT = TypeVar ("NDArrayT" , bound = np .ndarray )
968+ if sys .version_info >= (3 , 11 ):
969+ NDArrayT = TypeVar ("NDArrayT" , bound = np .ndarray )
970+ else :
971+ NDArrayT = TypeVar ("NDArrayT" , bound = np .ndarray [Any , Any ])
963972
964973DtypeNp = TypeVar ("DtypeNp" , bound = np .dtype [np .generic ])
965974KeysArgType : TypeAlias = Any
@@ -969,7 +978,7 @@ ListLikeExceptSeriesAndStr: TypeAlias = (
969978)
970979ListLikeU : TypeAlias = Sequence [Any ] | np_1darray | Series | Index
971980ListLikeHashable : TypeAlias = (
972- MutableSequence [HashableT ] | np_1darray | tuple [HashableT , ...] | range
981+ MutableSequence [HashableT0 ] | np_1darray | tuple [HashableT0 , ...] | range
973982)
974983
975984class SupportsDType (Protocol [GenericT_co ]):
@@ -1010,8 +1019,9 @@ SeriesDType: TypeAlias = (
10101019 | datetime .datetime # includes pd.Timestamp
10111020 | datetime .timedelta # includes pd.Timedelta
10121021)
1022+ S0 = TypeVar ("S0" , bound = SeriesDType , default = Any )
10131023S1 = TypeVar ("S1" , bound = SeriesDType , default = Any )
1014- # Like S1, but without `default=Any`.
1024+ # Like S0 and S1, but without `default=Any`.
10151025S2 = TypeVar ("S2" , bound = SeriesDType )
10161026S2_contra = TypeVar ("S2_contra" , bound = SeriesDType , contravariant = True )
10171027S2_NDT_contra = TypeVar (
@@ -1045,14 +1055,14 @@ IndexingInt: TypeAlias = (
10451055)
10461056
10471057# AxesData is used for data for Index
1048- AxesData : TypeAlias = Mapping [S3 , Any ] | Axes | KeysView [S3 ]
1058+ AxesData : TypeAlias = Mapping [S0 , Any ] | Axes | KeysView [S0 ]
10491059
10501060# Any plain Python or numpy function
10511061Function : TypeAlias = np .ufunc | Callable [..., Any ]
10521062# Use a distinct HashableT in shared types to avoid conflicts with
10531063# shared HashableT and HashableT#. This one can be used if the identical
10541064# type is need in a function that uses GroupByObjectNonScalar
1055- _HashableTa = TypeVar ("_HashableTa" , bound = Hashable )
1065+ _HashableTa = TypeVar ("_HashableTa" , bound = Hashable , default = Any )
10561066if TYPE_CHECKING : # noqa: PYI002
10571067 ByT = TypeVar (
10581068 "ByT" ,
@@ -1070,7 +1080,7 @@ if TYPE_CHECKING: # noqa: PYI002
10701080 | Scalar
10711081 | Period
10721082 | Interval [int | float | Timestamp | Timedelta ]
1073- | tuple ,
1083+ | tuple [ Any , ...] ,
10741084 )
10751085 # Use a distinct SeriesByT when using groupby with Series of known dtype.
10761086 # Essentially, an intersection between Series S1 TypeVar, and ByT TypeVar
@@ -1088,21 +1098,23 @@ if TYPE_CHECKING: # noqa: PYI002
10881098 | Period
10891099 | Interval [int | float | Timestamp | Timedelta ],
10901100 )
1091- GroupByObjectNonScalar : TypeAlias = (
1092- tuple [_HashableTa , ...]
1093- | list [_HashableTa ]
1094- | Function
1095- | list [Function ]
1096- | list [Series ]
1097- | np_ndarray
1098- | list [np_ndarray ]
1099- | Mapping [Label , Any ]
1100- | list [Mapping [Label , Any ]]
1101- | list [Index ]
1102- | Grouper
1103- | list [Grouper ]
1104- )
1105- GroupByObject : TypeAlias = Scalar | Index | GroupByObjectNonScalar | Series
1101+ GroupByObjectNonScalar : TypeAlias = (
1102+ tuple [_HashableTa , ...]
1103+ | list [_HashableTa ]
1104+ | Function
1105+ | list [Function ]
1106+ | list [Series ]
1107+ | np_ndarray
1108+ | list [np_ndarray ]
1109+ | Mapping [Label , Any ]
1110+ | list [Mapping [Label , Any ]]
1111+ | list [Index ]
1112+ | Grouper
1113+ | list [Grouper ]
1114+ )
1115+ GroupByObject : TypeAlias = (
1116+ Scalar | Index | GroupByObjectNonScalar [_HashableTa ] | Series
1117+ )
11061118
11071119StataDateFormat : TypeAlias = Literal [
11081120 "tc" ,
@@ -1125,10 +1137,10 @@ StataDateFormat: TypeAlias = Literal[
11251137# `DataFrame.replace` also accepts mappings of these.
11261138ReplaceValue : TypeAlias = (
11271139 Scalar
1128- | Pattern
1140+ | Pattern [ Any ]
11291141 | NAType
1130- | Sequence [Scalar | Pattern ]
1131- | Mapping [HashableT , ScalarT ]
1142+ | Sequence [Scalar | Pattern [ Any ] ]
1143+ | Mapping [HashableT0 , ScalarT0 ]
11321144 | Series
11331145 | None
11341146)
0 commit comments