2
2
from builtins import slice as _slice
3
3
from collections .abc import (
4
4
Callable ,
5
+ Hashable ,
6
+ Mapping ,
5
7
Sequence ,
6
8
)
7
9
import re
8
10
from typing import (
9
- Any ,
10
11
Generic ,
11
12
Literal ,
12
13
TypeVar ,
@@ -27,6 +28,7 @@ from pandas.core.base import NoNewAttributesMixin
27
28
from pandas ._libs .tslibs .nattype import NaTType
28
29
from pandas ._typing import (
29
30
AlignJoin ,
31
+ DtypeObj ,
30
32
Scalar ,
31
33
T ,
32
34
np_ndarray_bool ,
@@ -45,7 +47,7 @@ _T_BYTES = TypeVar("_T_BYTES", bound=Series[bytes] | Index[bytes])
45
47
# Used for the result of str.decode
46
48
_T_STR = TypeVar ("_T_STR" , bound = Series [str ] | Index [str ])
47
49
# Used for the result of str.partition
48
- _T_OBJECT = TypeVar ("_T_OBJECT" , bound = Series [ type [ object ]] | Index [ type [ object ]] )
50
+ _T_OBJECT = TypeVar ("_T_OBJECT" , bound = Series | Index )
49
51
50
52
class StringMethods (
51
53
NoNewAttributesMixin ,
@@ -57,163 +59,163 @@ class StringMethods(
57
59
@overload
58
60
def cat (
59
61
self ,
60
- * ,
61
- sep : str ,
62
- na_rep : str | None = ...,
63
- join : AlignJoin = ...,
64
- ) -> str : ...
65
- @overload
66
- def cat (
67
- self ,
68
- others : Literal [None ] = ...,
69
- * ,
70
- sep : str ,
71
- na_rep : str | None = ...,
72
- join : AlignJoin = ...,
62
+ others : None = None ,
63
+ sep : str | None = None ,
64
+ na_rep : str | None = None ,
65
+ join : AlignJoin = "left" ,
73
66
) -> str : ...
74
67
@overload
75
68
def cat (
76
69
self ,
77
70
others : (
78
71
Series [str ] | Index [str ] | pd .DataFrame | npt .NDArray [np .str_ ] | list [str ]
79
72
),
80
- sep : str = ... ,
81
- na_rep : str | None = ... ,
82
- join : AlignJoin = ... ,
73
+ sep : str | None = None ,
74
+ na_rep : str | None = None ,
75
+ join : AlignJoin = "left" ,
83
76
) -> _T_STR : ...
84
77
@overload
85
78
def split (
86
79
self ,
87
- pat : str | re .Pattern [str ] = ... ,
80
+ pat : str | re .Pattern [str ] | None = None ,
88
81
* ,
89
- n : int = ... ,
82
+ n : int = - 1 ,
90
83
expand : Literal [True ],
91
- regex : bool = ... ,
84
+ regex : bool | None = None ,
92
85
) -> _T_EXPANDING : ...
93
86
@overload
94
87
def split (
95
88
self ,
96
- pat : str | re .Pattern [str ] = ... ,
89
+ pat : str | re .Pattern [str ] | None = None ,
97
90
* ,
98
- n : int = ... ,
99
- expand : Literal [False ] = ... ,
100
- regex : bool = ... ,
91
+ n : int = - 1 ,
92
+ expand : Literal [False ] = False ,
93
+ regex : bool | None = None ,
101
94
) -> _T_LIST_STR : ...
102
95
@overload
103
96
def rsplit (
104
- self , pat : str = ... , * , n : int = ... , expand : Literal [True ]
97
+ self , pat : str | None = None , * , n : int = - 1 , expand : Literal [True ]
105
98
) -> _T_EXPANDING : ...
106
99
@overload
107
100
def rsplit (
108
- self , pat : str = ... , * , n : int = ... , expand : Literal [False ] = ...
101
+ self , pat : str | None = None , * , n : int = - 1 , expand : Literal [False ] = False
109
102
) -> _T_LIST_STR : ...
110
- @overload
111
- def partition (self , sep : str = ...) -> _T_EXPANDING : ...
112
- @overload
113
- def partition (self , * , expand : Literal [True ]) -> _T_EXPANDING : ...
114
- @overload
115
- def partition (self , sep : str , expand : Literal [True ]) -> _T_EXPANDING : ...
116
- @overload
103
+ @overload # expand=True
104
+ def partition (
105
+ self , sep : str = " " , expand : Literal [True ] = True
106
+ ) -> _T_EXPANDING : ...
107
+ @overload # expand=False (positional argument)
117
108
def partition (self , sep : str , expand : Literal [False ]) -> _T_OBJECT : ...
118
- @overload
119
- def partition (self , * , expand : Literal [False ]) -> _T_OBJECT : ...
120
- @overload
121
- def rpartition (self , sep : str = ...) -> _T_EXPANDING : ...
122
- @overload
123
- def rpartition (self , * , expand : Literal [True ]) -> _T_EXPANDING : ...
124
- @overload
125
- def rpartition (self , sep : str , expand : Literal [True ]) -> _T_EXPANDING : ...
126
- @overload
109
+ @overload # expand=False (keyword argument)
110
+ def partition (self , sep : str = " " , * , expand : Literal [False ]) -> _T_OBJECT : ...
111
+ @overload # expand=True
112
+ def rpartition (
113
+ self , sep : str = " " , expand : Literal [True ] = True
114
+ ) -> _T_EXPANDING : ...
115
+ @overload # expand=False (positional argument)
127
116
def rpartition (self , sep : str , expand : Literal [False ]) -> _T_OBJECT : ...
128
- @overload
129
- def rpartition (self , * , expand : Literal [False ]) -> _T_OBJECT : ...
130
- def get (self , i : int ) -> _T_STR : ...
117
+ @overload # expand=False (keyword argument)
118
+ def rpartition (self , sep : str = " " , * , expand : Literal [False ]) -> _T_OBJECT : ...
119
+ def get (self , i : int | Hashable ) -> _T_STR : ...
131
120
def join (self , sep : str ) -> _T_STR : ...
132
121
def contains (
133
122
self ,
134
123
pat : str | re .Pattern [str ],
135
- case : bool = ... ,
136
- flags : int = ... ,
124
+ case : bool = True ,
125
+ flags : int = 0 ,
137
126
na : Scalar | NaTType | None = ...,
138
- regex : bool = ... ,
127
+ regex : bool = True ,
139
128
) -> _T_BOOL : ...
140
129
def match (
141
130
self ,
142
131
pat : str | re .Pattern [str ],
143
- case : bool = ...,
144
- flags : int = ...,
145
- na : Any = ...,
132
+ case : bool = True ,
133
+ flags : int = 0 ,
134
+ na : Scalar | NaTType | None = ...,
135
+ ) -> _T_BOOL : ...
136
+ def fullmatch (
137
+ self ,
138
+ pat : str | re .Pattern [str ],
139
+ case : bool = True ,
140
+ flags : int = 0 ,
141
+ na : Scalar | NaTType | None = ...,
146
142
) -> _T_BOOL : ...
147
143
def replace (
148
144
self ,
149
145
pat : str | re .Pattern [str ],
150
146
repl : str | Callable [[re .Match [str ]], str ],
151
- n : int = ... ,
152
- case : bool | None = ... ,
153
- flags : int = ... ,
154
- regex : bool = ... ,
147
+ n : int = - 1 ,
148
+ case : bool | None = None ,
149
+ flags : int = 0 ,
150
+ regex : bool = False ,
155
151
) -> _T_STR : ...
156
152
def repeat (self , repeats : int | Sequence [int ]) -> _T_STR : ...
157
153
def pad (
158
154
self ,
159
155
width : int ,
160
- side : Literal ["left" , "right" , "both" ] = ... ,
161
- fillchar : str = ... ,
156
+ side : Literal ["left" , "right" , "both" ] = "left" ,
157
+ fillchar : str = " " ,
162
158
) -> _T_STR : ...
163
- def center (self , width : int , fillchar : str = ... ) -> _T_STR : ...
164
- def ljust (self , width : int , fillchar : str = ... ) -> _T_STR : ...
165
- def rjust (self , width : int , fillchar : str = ... ) -> _T_STR : ...
159
+ def center (self , width : int , fillchar : str = " " ) -> _T_STR : ...
160
+ def ljust (self , width : int , fillchar : str = " " ) -> _T_STR : ...
161
+ def rjust (self , width : int , fillchar : str = " " ) -> _T_STR : ...
166
162
def zfill (self , width : int ) -> _T_STR : ...
167
163
def slice (
168
- self , start : int | None = ... , stop : int | None = ... , step : int | None = ...
164
+ self , start : int | None = None , stop : int | None = None , step : int | None = None
169
165
) -> T : ...
170
166
def slice_replace (
171
- self , start : int | None = ... , stop : int | None = ... , repl : str | None = ...
167
+ self , start : int | None = None , stop : int | None = None , repl : str | None = None
172
168
) -> _T_STR : ...
173
- def decode (self , encoding : str , errors : str = ...) -> _T_STR : ...
174
- def encode (self , encoding : str , errors : str = ...) -> _T_BYTES : ...
175
- def strip (self , to_strip : str | None = ...) -> _T_STR : ...
176
- def lstrip (self , to_strip : str | None = ...) -> _T_STR : ...
177
- def rstrip (self , to_strip : str | None = ...) -> _T_STR : ...
169
+ def decode (
170
+ self , encoding : str , errors : str = "strict" , dtype : str | DtypeObj | None = None
171
+ ) -> _T_STR : ...
172
+ def encode (self , encoding : str , errors : str = "strict" ) -> _T_BYTES : ...
173
+ def strip (self , to_strip : str | None = None ) -> _T_STR : ...
174
+ def lstrip (self , to_strip : str | None = None ) -> _T_STR : ...
175
+ def rstrip (self , to_strip : str | None = None ) -> _T_STR : ...
176
+ def removeprefix (self , prefix : str ) -> _T_STR : ...
177
+ def removesuffix (self , suffix : str ) -> _T_STR : ...
178
178
def wrap (
179
179
self ,
180
180
width : int ,
181
- expand_tabs : bool | None = ...,
182
- replace_whitespace : bool | None = ...,
183
- drop_whitespace : bool | None = ...,
184
- break_long_words : bool | None = ...,
185
- break_on_hyphens : bool | None = ...,
181
+ * ,
182
+ # kwargs passed to textwrap.TextWrapper
183
+ expand_tabs : bool = True ,
184
+ replace_whitespace : bool = True ,
185
+ drop_whitespace : bool = True ,
186
+ break_long_words : bool = True ,
187
+ break_on_hyphens : bool = True ,
186
188
) -> _T_STR : ...
187
- def get_dummies (self , sep : str = ...) -> _T_EXPANDING : ...
188
- def translate (self , table : dict [int , int | str | None ] | None ) -> _T_STR : ...
189
- def count (self , pat : str , flags : int = ...) -> _T_INT : ...
190
- def startswith (self , pat : str | tuple [str , ...], na : Any = ...) -> _T_BOOL : ...
191
- def endswith (self , pat : str | tuple [str , ...], na : Any = ...) -> _T_BOOL : ...
192
- def findall (self , pat : str | re .Pattern [str ], flags : int = ...) -> _T_LIST_STR : ...
193
- @overload
189
+ def get_dummies (self , sep : str = "|" ) -> _T_EXPANDING : ...
190
+ def translate (self , table : Mapping [int , int | str | None ] | None ) -> _T_STR : ...
191
+ def count (self , pat : str , flags : int = 0 ) -> _T_INT : ...
192
+ def startswith (
193
+ self , pat : str | tuple [str , ...], na : Scalar | NaTType | None = ...
194
+ ) -> _T_BOOL : ...
195
+ def endswith (
196
+ self , pat : str | tuple [str , ...], na : Scalar | NaTType | None = ...
197
+ ) -> _T_BOOL : ...
198
+ def findall (self , pat : str | re .Pattern [str ], flags : int = 0 ) -> _T_LIST_STR : ...
199
+ @overload # expand=True
194
200
def extract (
195
- self ,
196
- pat : str | re .Pattern [str ],
197
- flags : int = ...,
198
- * ,
199
- expand : Literal [True ] = ...,
201
+ self , pat : str | re .Pattern [str ], flags : int = 0 , expand : Literal [True ] = True
200
202
) -> pd .DataFrame : ...
201
- @overload
203
+ @overload # expand=False (positional argument)
202
204
def extract (
203
205
self , pat : str | re .Pattern [str ], flags : int , expand : Literal [False ]
204
206
) -> _T_OBJECT : ...
205
- @overload
207
+ @overload # expand=False (keyword argument)
206
208
def extract (
207
- self , pat : str | re .Pattern [str ], flags : int = ... , * , expand : Literal [False ]
209
+ self , pat : str | re .Pattern [str ], flags : int = 0 , * , expand : Literal [False ]
208
210
) -> _T_OBJECT : ...
209
211
def extractall (
210
- self , pat : str | re .Pattern [str ], flags : int = ...
212
+ self , pat : str | re .Pattern [str ], flags : int = 0
211
213
) -> pd .DataFrame : ...
212
- def find (self , sub : str , start : int = ... , end : int | None = ... ) -> _T_INT : ...
213
- def rfind (self , sub : str , start : int = ... , end : int | None = ... ) -> _T_INT : ...
214
+ def find (self , sub : str , start : int = 0 , end : int | None = None ) -> _T_INT : ...
215
+ def rfind (self , sub : str , start : int = 0 , end : int | None = None ) -> _T_INT : ...
214
216
def normalize (self , form : Literal ["NFC" , "NFKC" , "NFD" , "NFKD" ]) -> _T_STR : ...
215
- def index (self , sub : str , start : int = ... , end : int | None = ... ) -> _T_INT : ...
216
- def rindex (self , sub : str , start : int = ... , end : int | None = ... ) -> _T_INT : ...
217
+ def index (self , sub : str , start : int = 0 , end : int | None = None ) -> _T_INT : ...
218
+ def rindex (self , sub : str , start : int = 0 , end : int | None = None ) -> _T_INT : ...
217
219
def len (self ) -> _T_INT : ...
218
220
def lower (self ) -> _T_STR : ...
219
221
def upper (self ) -> _T_STR : ...
@@ -230,12 +232,3 @@ class StringMethods(
230
232
def istitle (self ) -> _T_BOOL : ...
231
233
def isnumeric (self ) -> _T_BOOL : ...
232
234
def isdecimal (self ) -> _T_BOOL : ...
233
- def fullmatch (
234
- self ,
235
- pat : str | re .Pattern [str ],
236
- case : bool = ...,
237
- flags : int = ...,
238
- na : Any = ...,
239
- ) -> _T_BOOL : ...
240
- def removeprefix (self , prefix : str ) -> _T_STR : ...
241
- def removesuffix (self , suffix : str ) -> _T_STR : ...
0 commit comments