@@ -31,23 +31,24 @@ from pandas._typing import (
31
31
np_ndarray_bool ,
32
32
)
33
33
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 ]])
48
48
49
49
class 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 ],
51
52
):
52
53
def __init__ (self , data : T ) -> None : ...
53
54
def __getitem__ (self , key : slice | int ) -> T : ...
@@ -82,7 +83,7 @@ class StringMethods(
82
83
@overload
83
84
def split (
84
85
self , pat : str = ..., * , n : int = ..., expand : Literal [True ], regex : bool = ...
85
- ) -> _TS : ...
86
+ ) -> _T_EXPANDING : ...
86
87
@overload
87
88
def split (
88
89
self ,
@@ -91,46 +92,48 @@ class StringMethods(
91
92
n : int = ...,
92
93
expand : Literal [False ] = ...,
93
94
regex : bool = ...,
94
- ) -> _TS2 : ...
95
+ ) -> _T_LIST_STR : ...
95
96
@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 : ...
97
100
@overload
98
101
def rsplit (
99
102
self , pat : str = ..., * , n : int = ..., expand : Literal [False ] = ...
100
- ) -> _TS2 : ...
103
+ ) -> _T_LIST_STR : ...
101
104
@overload
102
- def partition (self , sep : str = ...) -> _TS : ...
105
+ def partition (self , sep : str = ...) -> _T_EXPANDING : ...
103
106
@overload
104
- def partition (self , * , expand : Literal [True ]) -> _TS : ...
107
+ def partition (self , * , expand : Literal [True ]) -> _T_EXPANDING : ...
105
108
@overload
106
- def partition (self , sep : str , expand : Literal [True ]) -> _TS : ...
109
+ def partition (self , sep : str , expand : Literal [True ]) -> _T_EXPANDING : ...
107
110
@overload
108
- def partition (self , sep : str , expand : Literal [False ]) -> _TO : ...
111
+ def partition (self , sep : str , expand : Literal [False ]) -> _T_OBJECT : ...
109
112
@overload
110
- def partition (self , * , expand : Literal [False ]) -> _TO : ...
113
+ def partition (self , * , expand : Literal [False ]) -> _T_OBJECT : ...
111
114
@overload
112
- def rpartition (self , sep : str = ...) -> _TS : ...
115
+ def rpartition (self , sep : str = ...) -> _T_EXPANDING : ...
113
116
@overload
114
- def rpartition (self , * , expand : Literal [True ]) -> _TS : ...
117
+ def rpartition (self , * , expand : Literal [True ]) -> _T_EXPANDING : ...
115
118
@overload
116
- def rpartition (self , sep : str , expand : Literal [True ]) -> _TS : ...
119
+ def rpartition (self , sep : str , expand : Literal [True ]) -> _T_EXPANDING : ...
117
120
@overload
118
- def rpartition (self , sep : str , expand : Literal [False ]) -> _TO : ...
121
+ def rpartition (self , sep : str , expand : Literal [False ]) -> _T_OBJECT : ...
119
122
@overload
120
- def rpartition (self , * , expand : Literal [False ]) -> _TO : ...
123
+ def rpartition (self , * , expand : Literal [False ]) -> _T_OBJECT : ...
121
124
def get (self , i : int ) -> T : ...
122
- def join (self , sep : str ) -> _TD : ...
125
+ def join (self , sep : str ) -> _T_STR : ...
123
126
def contains (
124
127
self ,
125
128
pat : str | re .Pattern [str ],
126
129
case : bool = ...,
127
130
flags : int = ...,
128
131
na : Scalar | NaTType | None = ...,
129
132
regex : bool = ...,
130
- ) -> _TM : ...
133
+ ) -> _T_BOOL : ...
131
134
def match (
132
135
self , pat : str , case : bool = ..., flags : int = ..., na : Any = ...
133
- ) -> _TM : ...
136
+ ) -> _T_BOOL : ...
134
137
def replace (
135
138
self ,
136
139
pat : str ,
@@ -157,8 +160,8 @@ class StringMethods(
157
160
def slice_replace (
158
161
self , start : int | None = ..., stop : int | None = ..., repl : str | None = ...
159
162
) -> 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 : ...
162
165
def strip (self , to_strip : str | None = ...) -> T : ...
163
166
def lstrip (self , to_strip : str | None = ...) -> T : ...
164
167
def rstrip (self , to_strip : str | None = ...) -> T : ...
@@ -171,44 +174,46 @@ class StringMethods(
171
174
break_long_words : bool | None = ...,
172
175
break_on_hyphens : bool | None = ...,
173
176
) -> T : ...
174
- def get_dummies (self , sep : str = ...) -> _TS : ...
177
+ def get_dummies (self , sep : str = ...) -> _T_EXPANDING : ...
175
178
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 : ...
180
183
@overload
181
184
def extract (
182
185
self , pat : str , flags : int = ..., * , expand : Literal [True ] = ...
183
186
) -> pd .DataFrame : ...
184
187
@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 : ...
186
189
@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 : ...
188
193
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 : ...
191
196
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 : ...
195
200
def lower (self ) -> T : ...
196
201
def upper (self ) -> T : ...
197
202
def title (self ) -> T : ...
198
203
def capitalize (self ) -> T : ...
199
204
def swapcase (self ) -> T : ...
200
205
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 : ...
210
215
def fullmatch (
211
216
self , pat : str , case : bool = ..., flags : int = ..., na : Any = ...
212
- ) -> _TM : ...
217
+ ) -> _T_BOOL : ...
213
218
def removeprefix (self , prefix : str ) -> T : ...
214
219
def removesuffix (self , suffix : str ) -> T : ...
0 commit comments