@@ -77,6 +77,7 @@ from pandas.tseries.offsets import (
7777P = ParamSpec ("P" )
7878
7979HashableT = TypeVar ("HashableT" , bound = Hashable )
80+ HashableT0 = TypeVar ("HashableT0" , bound = Hashable , default = Any )
8081HashableT1 = TypeVar ("HashableT1" , bound = Hashable )
8182HashableT2 = TypeVar ("HashableT2" , bound = Hashable )
8283HashableT3 = TypeVar ("HashableT3" , bound = Hashable )
@@ -776,7 +777,7 @@ XMLParsers: TypeAlias = Literal["lxml", "etree"]
776777HTMLFlavors : TypeAlias = Literal ["lxml" , "html5lib" , "bs4" ]
777778
778779# Interval closed type
779- IntervalT = TypeVar ("IntervalT" , bound = Interval )
780+ IntervalT = TypeVar ("IntervalT" , bound = Interval , default = Interval )
780781IntervalLeftRight : TypeAlias = Literal ["left" , "right" ]
781782IntervalClosedType : TypeAlias = IntervalLeftRight | Literal ["both" , "neither" ]
782783
@@ -874,7 +875,11 @@ ExcelWriterMergeCells: TypeAlias = bool | Literal["columns"]
874875
875876# read_csv: usecols
876877UsecolsArgType : TypeAlias = (
877- SequenceNotStr [Hashable ] | range | AnyArrayLike | Callable [[HashableT ], bool ] | None
878+ SequenceNotStr [Hashable ]
879+ | range
880+ | AnyArrayLike
881+ | Callable [[HashableT0 ], bool ]
882+ | None
878883)
879884
880885# maintain the sub-type of any hashable sequence
@@ -920,6 +925,7 @@ PyArrowNotStrDtypeArg: TypeAlias = (
920925StrLike : TypeAlias = str | np .str_
921926
922927ScalarT = TypeVar ("ScalarT" , bound = Scalar )
928+ ScalarT0 = TypeVar ("ScalarT0" , bound = Scalar , default = Scalar )
923929# Refine the definitions below in 3.9 to use the specialized type.
924930np_num : TypeAlias = np .bool | np .integer | np .floating | np .complexfloating
925931np_ndarray_intp : TypeAlias = npt .NDArray [np .intp ]
@@ -974,7 +980,7 @@ ListLikeExceptSeriesAndStr: TypeAlias = (
974980)
975981ListLikeU : TypeAlias = Sequence [Any ] | np_1darray | Series | Index
976982ListLikeHashable : TypeAlias = (
977- MutableSequence [HashableT ] | np_1darray | tuple [HashableT , ...] | range
983+ MutableSequence [HashableT0 ] | np_1darray | tuple [HashableT0 , ...] | range
978984)
979985
980986class SupportsDType (Protocol [GenericT_co ]):
@@ -1015,8 +1021,9 @@ SeriesDType: TypeAlias = (
10151021 | datetime .datetime # includes pd.Timestamp
10161022 | datetime .timedelta # includes pd.Timedelta
10171023)
1024+ S0 = TypeVar ("S0" , bound = SeriesDType , default = Any )
10181025S1 = TypeVar ("S1" , bound = SeriesDType , default = Any )
1019- # Like S1, but without `default=Any`.
1026+ # Like S0 and S1, but without `default=Any`.
10201027S2 = TypeVar ("S2" , bound = SeriesDType )
10211028S2_contra = TypeVar ("S2_contra" , bound = SeriesDType , contravariant = True )
10221029S2_NDT_contra = TypeVar (
@@ -1050,14 +1057,14 @@ IndexingInt: TypeAlias = (
10501057)
10511058
10521059# AxesData is used for data for Index
1053- AxesData : TypeAlias = Mapping [S3 , Any ] | Axes | KeysView [S3 ]
1060+ AxesData : TypeAlias = Mapping [S0 , Any ] | Axes | KeysView [S0 ]
10541061
10551062# Any plain Python or numpy function
10561063Function : TypeAlias = np .ufunc | Callable [..., Any ]
10571064# Use a distinct HashableT in shared types to avoid conflicts with
10581065# shared HashableT and HashableT#. This one can be used if the identical
10591066# type is need in a function that uses GroupByObjectNonScalar
1060- _HashableTa = TypeVar ("_HashableTa" , bound = Hashable )
1067+ _HashableTa = TypeVar ("_HashableTa" , bound = Hashable , default = Any )
10611068if TYPE_CHECKING : # noqa: PYI002
10621069 ByT = TypeVar (
10631070 "ByT" ,
@@ -1075,7 +1082,7 @@ if TYPE_CHECKING: # noqa: PYI002
10751082 | Scalar
10761083 | Period
10771084 | Interval [int | float | Timestamp | Timedelta ]
1078- | tuple ,
1085+ | tuple [ Any , ...] ,
10791086 )
10801087 # Use a distinct SeriesByT when using groupby with Series of known dtype.
10811088 # Essentially, an intersection between Series S1 TypeVar, and ByT TypeVar
@@ -1093,21 +1100,23 @@ if TYPE_CHECKING: # noqa: PYI002
10931100 | Period
10941101 | Interval [int | float | Timestamp | Timedelta ],
10951102 )
1096- GroupByObjectNonScalar : TypeAlias = (
1097- tuple [_HashableTa , ...]
1098- | list [_HashableTa ]
1099- | Function
1100- | list [Function ]
1101- | list [Series ]
1102- | np_ndarray
1103- | list [np_ndarray ]
1104- | Mapping [Label , Any ]
1105- | list [Mapping [Label , Any ]]
1106- | list [Index ]
1107- | Grouper
1108- | list [Grouper ]
1109- )
1110- GroupByObject : TypeAlias = Scalar | Index | GroupByObjectNonScalar | Series
1103+ GroupByObjectNonScalar : TypeAlias = (
1104+ tuple [_HashableTa , ...]
1105+ | list [_HashableTa ]
1106+ | Function
1107+ | list [Function ]
1108+ | list [Series ]
1109+ | np_ndarray
1110+ | list [np_ndarray ]
1111+ | Mapping [Label , Any ]
1112+ | list [Mapping [Label , Any ]]
1113+ | list [Index ]
1114+ | Grouper
1115+ | list [Grouper ]
1116+ )
1117+ GroupByObject : TypeAlias = (
1118+ Scalar | Index | GroupByObjectNonScalar [_HashableTa ] | Series
1119+ )
11111120
11121121StataDateFormat : TypeAlias = Literal [
11131122 "tc" ,
@@ -1130,10 +1139,10 @@ StataDateFormat: TypeAlias = Literal[
11301139# `DataFrame.replace` also accepts mappings of these.
11311140ReplaceValue : TypeAlias = (
11321141 Scalar
1133- | Pattern
1142+ | Pattern [ Any ]
11341143 | NAType
1135- | Sequence [Scalar | Pattern ]
1136- | Mapping [HashableT , ScalarT ]
1144+ | Sequence [Scalar | Pattern [ Any ] ]
1145+ | Mapping [HashableT0 , ScalarT0 ]
11371146 | Series
11381147 | None
11391148)
0 commit comments