@@ -31,23 +31,24 @@ from pandas._typing import (
3131 np_ndarray_bool ,
3232)
3333
34- # The _TS type is what is used for the result of str.split with expand=True
35- _TS = TypeVar ("_TS " , bound = DataFrame | MultiIndex )
36- # The _TS2 type is what is used for the result of str.split with expand=False
37- _TS2 = TypeVar ("_TS2 " , bound = Series [list [str ]] | Index [list [str ]])
38- # The _TM type is what is used for the result of str.match
39- _TM = TypeVar ("_TM " , bound = Series [bool ] | np_ndarray_bool )
40- # The _TI type is what is used for the result of str.index / str.find
41- _TI = TypeVar ("_TI " , bound = Series [int ] | Index [int ])
42- # The _TE type is what is used for the result of str.encode
43- _TE = TypeVar ("_TE " , bound = Series [bytes ] | Index [bytes ])
44- # The _TD type is what is used for the result of str.encode
45- _TD = TypeVar ("_TD " , bound = Series [str ] | Index [str ])
46- # The _TO type is what is used for the result of str.encode
47- _TO = TypeVar ("_TO " , bound = Series [type [object ]] | Index [type [object ]])
34+ # Used for the result of str.split with expand=True
35+ _T_EXPANDING = TypeVar ("_T_EXPANDING " , bound = DataFrame | MultiIndex )
36+ # Used for the result of str.split with expand=False
37+ _T_LIST_STR = TypeVar ("_T_LIST_STR " , bound = Series [list [str ]] | Index [list [str ]])
38+ # Used for the result of str.match
39+ _T_BOOL = TypeVar ("_T_BOOL " , bound = Series [bool ] | np_ndarray_bool )
40+ # Used for the result of str.index / str.find
41+ _T_INT = TypeVar ("_T_INT " , bound = Series [int ] | Index [int ])
42+ # Used for the result of str.encode
43+ _T_BYTES = TypeVar ("_T_BYTES " , bound = Series [bytes ] | Index [bytes ])
44+ # Used for the result of str.decode
45+ _T_STR = TypeVar ("_T_STR " , bound = Series [str ] | Index [str ])
46+ # Used for the result of str.partition
47+ _T_OBJECT = TypeVar ("_T_OBJECT " , bound = Series [type [object ]] | Index [type [object ]])
4848
4949class StringMethods (
50- NoNewAttributesMixin , Generic [T , _TS , _TM , _TS2 , _TI , _TE , _TD , _TO ]
50+ NoNewAttributesMixin ,
51+ Generic [T , _T_EXPANDING , _T_BOOL , _T_LIST_STR , _T_INT , _T_BYTES , _T_STR , _T_OBJECT ],
5152):
5253 def __init__ (self , data : T ) -> None : ...
5354 def __getitem__ (self , key : slice | int ) -> T : ...
@@ -82,7 +83,7 @@ class StringMethods(
8283 @overload
8384 def split (
8485 self , pat : str = ..., * , n : int = ..., expand : Literal [True ], regex : bool = ...
85- ) -> _TS : ...
86+ ) -> _T_EXPANDING : ...
8687 @overload
8788 def split (
8889 self ,
@@ -91,46 +92,48 @@ class StringMethods(
9192 n : int = ...,
9293 expand : Literal [False ] = ...,
9394 regex : bool = ...,
94- ) -> _TS2 : ...
95+ ) -> _T_LIST_STR : ...
9596 @overload
96- def rsplit (self , pat : str = ..., * , n : int = ..., expand : Literal [True ]) -> _TS : ...
97+ def rsplit (
98+ self , pat : str = ..., * , n : int = ..., expand : Literal [True ]
99+ ) -> _T_EXPANDING : ...
97100 @overload
98101 def rsplit (
99102 self , pat : str = ..., * , n : int = ..., expand : Literal [False ] = ...
100- ) -> _TS2 : ...
103+ ) -> _T_LIST_STR : ...
101104 @overload
102- def partition (self , sep : str = ...) -> _TS : ...
105+ def partition (self , sep : str = ...) -> _T_EXPANDING : ...
103106 @overload
104- def partition (self , * , expand : Literal [True ]) -> _TS : ...
107+ def partition (self , * , expand : Literal [True ]) -> _T_EXPANDING : ...
105108 @overload
106- def partition (self , sep : str , expand : Literal [True ]) -> _TS : ...
109+ def partition (self , sep : str , expand : Literal [True ]) -> _T_EXPANDING : ...
107110 @overload
108- def partition (self , sep : str , expand : Literal [False ]) -> _TO : ...
111+ def partition (self , sep : str , expand : Literal [False ]) -> _T_OBJECT : ...
109112 @overload
110- def partition (self , * , expand : Literal [False ]) -> _TO : ...
113+ def partition (self , * , expand : Literal [False ]) -> _T_OBJECT : ...
111114 @overload
112- def rpartition (self , sep : str = ...) -> _TS : ...
115+ def rpartition (self , sep : str = ...) -> _T_EXPANDING : ...
113116 @overload
114- def rpartition (self , * , expand : Literal [True ]) -> _TS : ...
117+ def rpartition (self , * , expand : Literal [True ]) -> _T_EXPANDING : ...
115118 @overload
116- def rpartition (self , sep : str , expand : Literal [True ]) -> _TS : ...
119+ def rpartition (self , sep : str , expand : Literal [True ]) -> _T_EXPANDING : ...
117120 @overload
118- def rpartition (self , sep : str , expand : Literal [False ]) -> _TO : ...
121+ def rpartition (self , sep : str , expand : Literal [False ]) -> _T_OBJECT : ...
119122 @overload
120- def rpartition (self , * , expand : Literal [False ]) -> _TO : ...
123+ def rpartition (self , * , expand : Literal [False ]) -> _T_OBJECT : ...
121124 def get (self , i : int ) -> T : ...
122- def join (self , sep : str ) -> _TD : ...
125+ def join (self , sep : str ) -> _T_STR : ...
123126 def contains (
124127 self ,
125128 pat : str | re .Pattern [str ],
126129 case : bool = ...,
127130 flags : int = ...,
128131 na : Scalar | NaTType | None = ...,
129132 regex : bool = ...,
130- ) -> _TM : ...
133+ ) -> _T_BOOL : ...
131134 def match (
132135 self , pat : str , case : bool = ..., flags : int = ..., na : Any = ...
133- ) -> _TM : ...
136+ ) -> _T_BOOL : ...
134137 def replace (
135138 self ,
136139 pat : str ,
@@ -157,8 +160,8 @@ class StringMethods(
157160 def slice_replace (
158161 self , start : int | None = ..., stop : int | None = ..., repl : str | None = ...
159162 ) -> T : ...
160- def decode (self , encoding : str , errors : str = ...) -> _TD : ...
161- def encode (self , encoding : str , errors : str = ...) -> _TE : ...
163+ def decode (self , encoding : str , errors : str = ...) -> _T_STR : ...
164+ def encode (self , encoding : str , errors : str = ...) -> _T_BYTES : ...
162165 def strip (self , to_strip : str | None = ...) -> T : ...
163166 def lstrip (self , to_strip : str | None = ...) -> T : ...
164167 def rstrip (self , to_strip : str | None = ...) -> T : ...
@@ -171,44 +174,46 @@ class StringMethods(
171174 break_long_words : bool | None = ...,
172175 break_on_hyphens : bool | None = ...,
173176 ) -> T : ...
174- def get_dummies (self , sep : str = ...) -> _TS : ...
177+ def get_dummies (self , sep : str = ...) -> _T_EXPANDING : ...
175178 def translate (self , table : dict [int , int | str | None ] | None ) -> T : ...
176- def count (self , pat : str , flags : int = ...) -> _TI : ...
177- def startswith (self , pat : str | tuple [str , ...], na : Any = ...) -> _TM : ...
178- def endswith (self , pat : str | tuple [str , ...], na : Any = ...) -> _TM : ...
179- def findall (self , pat : str , flags : int = ...) -> _TS2 : ...
179+ def count (self , pat : str , flags : int = ...) -> _T_INT : ...
180+ def startswith (self , pat : str | tuple [str , ...], na : Any = ...) -> _T_BOOL : ...
181+ def endswith (self , pat : str | tuple [str , ...], na : Any = ...) -> _T_BOOL : ...
182+ def findall (self , pat : str , flags : int = ...) -> _T_LIST_STR : ...
180183 @overload
181184 def extract (
182185 self , pat : str , flags : int = ..., * , expand : Literal [True ] = ...
183186 ) -> pd .DataFrame : ...
184187 @overload
185- def extract (self , pat : str , flags : int , expand : Literal [False ]) -> _TO : ...
188+ def extract (self , pat : str , flags : int , expand : Literal [False ]) -> _T_OBJECT : ...
186189 @overload
187- def extract (self , pat : str , flags : int = ..., * , expand : Literal [False ]) -> _TO : ...
190+ def extract (
191+ self , pat : str , flags : int = ..., * , expand : Literal [False ]
192+ ) -> _T_OBJECT : ...
188193 def extractall (self , pat : str , flags : int = ...) -> pd .DataFrame : ...
189- def find (self , sub : str , start : int = ..., end : int | None = ...) -> _TI : ...
190- def rfind (self , sub : str , start : int = ..., end : int | None = ...) -> _TI : ...
194+ def find (self , sub : str , start : int = ..., end : int | None = ...) -> _T_INT : ...
195+ def rfind (self , sub : str , start : int = ..., end : int | None = ...) -> _T_INT : ...
191196 def normalize (self , form : Literal ["NFC" , "NFKC" , "NFD" , "NFKD" ]) -> T : ...
192- def index (self , sub : str , start : int = ..., end : int | None = ...) -> _TI : ...
193- def rindex (self , sub : str , start : int = ..., end : int | None = ...) -> _TI : ...
194- def len (self ) -> _TI : ...
197+ def index (self , sub : str , start : int = ..., end : int | None = ...) -> _T_INT : ...
198+ def rindex (self , sub : str , start : int = ..., end : int | None = ...) -> _T_INT : ...
199+ def len (self ) -> _T_INT : ...
195200 def lower (self ) -> T : ...
196201 def upper (self ) -> T : ...
197202 def title (self ) -> T : ...
198203 def capitalize (self ) -> T : ...
199204 def swapcase (self ) -> T : ...
200205 def casefold (self ) -> T : ...
201- def isalnum (self ) -> _TM : ...
202- def isalpha (self ) -> _TM : ...
203- def isdigit (self ) -> _TM : ...
204- def isspace (self ) -> _TM : ...
205- def islower (self ) -> _TM : ...
206- def isupper (self ) -> _TM : ...
207- def istitle (self ) -> _TM : ...
208- def isnumeric (self ) -> _TM : ...
209- def isdecimal (self ) -> _TM : ...
206+ def isalnum (self ) -> _T_BOOL : ...
207+ def isalpha (self ) -> _T_BOOL : ...
208+ def isdigit (self ) -> _T_BOOL : ...
209+ def isspace (self ) -> _T_BOOL : ...
210+ def islower (self ) -> _T_BOOL : ...
211+ def isupper (self ) -> _T_BOOL : ...
212+ def istitle (self ) -> _T_BOOL : ...
213+ def isnumeric (self ) -> _T_BOOL : ...
214+ def isdecimal (self ) -> _T_BOOL : ...
210215 def fullmatch (
211216 self , pat : str , case : bool = ..., flags : int = ..., na : Any = ...
212- ) -> _TM : ...
217+ ) -> _T_BOOL : ...
213218 def removeprefix (self , prefix : str ) -> T : ...
214219 def removesuffix (self , suffix : str ) -> T : ...
0 commit comments