pixeltable 0.2.13__py3-none-any.whl → 0.2.15__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pixeltable might be problematic. Click here for more details.
- pixeltable/__init__.py +1 -1
- pixeltable/__version__.py +2 -2
- pixeltable/catalog/column.py +8 -3
- pixeltable/catalog/globals.py +8 -0
- pixeltable/catalog/table.py +25 -9
- pixeltable/catalog/table_version.py +30 -55
- pixeltable/catalog/view.py +1 -1
- pixeltable/env.py +4 -4
- pixeltable/exec/__init__.py +2 -1
- pixeltable/exec/row_update_node.py +61 -0
- pixeltable/exec/{sql_scan_node.py → sql_node.py} +120 -56
- pixeltable/exprs/__init__.py +1 -1
- pixeltable/exprs/arithmetic_expr.py +41 -16
- pixeltable/exprs/expr.py +72 -22
- pixeltable/exprs/function_call.py +64 -29
- pixeltable/exprs/globals.py +5 -1
- pixeltable/exprs/inline_array.py +18 -11
- pixeltable/exprs/method_ref.py +63 -0
- pixeltable/ext/__init__.py +9 -0
- pixeltable/ext/functions/__init__.py +8 -0
- pixeltable/ext/functions/whisperx.py +45 -5
- pixeltable/ext/functions/yolox.py +60 -14
- pixeltable/func/callable_function.py +12 -4
- pixeltable/func/expr_template_function.py +1 -1
- pixeltable/func/function.py +12 -2
- pixeltable/func/function_registry.py +24 -9
- pixeltable/func/udf.py +32 -4
- pixeltable/functions/__init__.py +1 -1
- pixeltable/functions/fireworks.py +33 -0
- pixeltable/functions/huggingface.py +96 -6
- pixeltable/functions/image.py +226 -41
- pixeltable/functions/json.py +46 -0
- pixeltable/functions/openai.py +214 -0
- pixeltable/functions/string.py +195 -218
- pixeltable/functions/timestamp.py +210 -0
- pixeltable/functions/together.py +106 -0
- pixeltable/functions/video.py +2 -2
- pixeltable/functions/{eval.py → vision.py} +170 -27
- pixeltable/functions/whisper.py +32 -0
- pixeltable/io/__init__.py +1 -1
- pixeltable/io/external_store.py +2 -2
- pixeltable/io/globals.py +133 -1
- pixeltable/io/pandas.py +82 -31
- pixeltable/iterators/video.py +55 -23
- pixeltable/metadata/__init__.py +1 -1
- pixeltable/metadata/converters/convert_18.py +39 -0
- pixeltable/metadata/notes.py +10 -0
- pixeltable/plan.py +76 -1
- pixeltable/store.py +65 -28
- pixeltable/tool/create_test_db_dump.py +8 -9
- pixeltable/tool/doc_plugins/griffe.py +4 -0
- pixeltable/type_system.py +84 -63
- {pixeltable-0.2.13.dist-info → pixeltable-0.2.15.dist-info}/METADATA +2 -2
- {pixeltable-0.2.13.dist-info → pixeltable-0.2.15.dist-info}/RECORD +57 -51
- pixeltable/exprs/image_member_access.py +0 -96
- {pixeltable-0.2.13.dist-info → pixeltable-0.2.15.dist-info}/LICENSE +0 -0
- {pixeltable-0.2.13.dist-info → pixeltable-0.2.15.dist-info}/WHEEL +0 -0
- {pixeltable-0.2.13.dist-info → pixeltable-0.2.15.dist-info}/entry_points.txt +0 -0
pixeltable/functions/string.py
CHANGED
|
@@ -15,49 +15,46 @@ t.select(pxt_str.capitalize(t.str_col)).collect()
|
|
|
15
15
|
from typing import Any, Optional
|
|
16
16
|
|
|
17
17
|
import pixeltable.func as func
|
|
18
|
-
from pixeltable.type_system import StringType
|
|
19
18
|
from pixeltable.utils.code import local_public_names
|
|
20
19
|
|
|
21
20
|
|
|
22
|
-
@func.udf
|
|
23
|
-
def capitalize(
|
|
21
|
+
@func.udf(is_method=True)
|
|
22
|
+
def capitalize(self: str) -> str:
|
|
24
23
|
"""
|
|
25
|
-
Return
|
|
24
|
+
Return string with its first character capitalized and the rest lowercased.
|
|
26
25
|
|
|
27
26
|
Equivalent to [`str.capitalize()`](https://docs.python.org/3/library/stdtypes.html#str.capitalize).
|
|
28
27
|
"""
|
|
29
|
-
return
|
|
28
|
+
return self.capitalize()
|
|
30
29
|
|
|
31
|
-
@func.udf
|
|
32
|
-
def casefold(
|
|
30
|
+
@func.udf(is_method=True)
|
|
31
|
+
def casefold(self: str) -> str:
|
|
33
32
|
"""
|
|
34
|
-
Return a casefolded copy of
|
|
33
|
+
Return a casefolded copy of string.
|
|
35
34
|
|
|
36
35
|
Equivalent to [`str.casefold()`](https://docs.python.org/3/library/stdtypes.html#str.casefold).
|
|
37
36
|
"""
|
|
38
|
-
return
|
|
37
|
+
return self.casefold()
|
|
39
38
|
|
|
40
|
-
@func.udf
|
|
41
|
-
def center(
|
|
39
|
+
@func.udf(is_method=True)
|
|
40
|
+
def center(self: str, width: int, fillchar: str = ' ') -> str:
|
|
42
41
|
"""
|
|
43
42
|
Return a centered string of length `width`.
|
|
44
43
|
|
|
45
44
|
Equivalent to [`str.center()`](https://docs.python.org/3/library/stdtypes.html#str.center).
|
|
46
45
|
|
|
47
46
|
Args:
|
|
48
|
-
s: String.
|
|
49
47
|
width: Total width of the resulting string.
|
|
50
48
|
fillchar: Character used for padding.
|
|
51
49
|
"""
|
|
52
|
-
return
|
|
50
|
+
return self.center(width, fillchar)
|
|
53
51
|
|
|
54
|
-
@func.udf
|
|
55
|
-
def contains(
|
|
52
|
+
@func.udf(is_method=True)
|
|
53
|
+
def contains(self: str, pattern: str, case: bool = True, flags: int = 0, regex: bool = True) -> bool:
|
|
56
54
|
"""
|
|
57
|
-
Test if pattern or regex
|
|
55
|
+
Test if string contains pattern or regex.
|
|
58
56
|
|
|
59
57
|
Args:
|
|
60
|
-
s: String.
|
|
61
58
|
pattern: string literal or regular expression
|
|
62
59
|
case: if False, ignore case
|
|
63
60
|
flags: [flags](https://docs.python.org/3/library/re.html#flags) for the `re` module
|
|
@@ -67,103 +64,97 @@ def contains(s: str, pattern: str, case: bool = True, flags: int = 0, regex: boo
|
|
|
67
64
|
import re
|
|
68
65
|
if not case:
|
|
69
66
|
flags |= re.IGNORECASE
|
|
70
|
-
return bool(re.search(pattern,
|
|
67
|
+
return bool(re.search(pattern, self, flags))
|
|
71
68
|
else:
|
|
72
69
|
if case:
|
|
73
|
-
return pattern in
|
|
70
|
+
return pattern in self
|
|
74
71
|
else:
|
|
75
|
-
return pattern.lower() in
|
|
72
|
+
return pattern.lower() in self.lower()
|
|
76
73
|
|
|
77
|
-
@func.udf
|
|
78
|
-
def count(
|
|
74
|
+
@func.udf(is_method=True)
|
|
75
|
+
def count(self: str, pattern: str, flags: int = 0) -> int:
|
|
79
76
|
"""
|
|
80
|
-
Count occurrences of pattern or regex
|
|
77
|
+
Count occurrences of pattern or regex.
|
|
81
78
|
|
|
82
79
|
Args:
|
|
83
|
-
s: String.
|
|
84
80
|
pattern: string literal or regular expression
|
|
85
81
|
flags: [flags](https://docs.python.org/3/library/re.html#flags) for the `re` module
|
|
86
82
|
"""
|
|
87
83
|
import re
|
|
88
84
|
from builtins import len
|
|
89
|
-
return len(re.findall(pattern,
|
|
85
|
+
return len(re.findall(pattern, self, flags))
|
|
90
86
|
|
|
91
|
-
@func.udf
|
|
92
|
-
def endswith(
|
|
87
|
+
@func.udf(is_method=True)
|
|
88
|
+
def endswith(self: str, pattern: str) -> bool:
|
|
93
89
|
"""
|
|
94
90
|
Return `True` if the string ends with the specified suffix, otherwise return `False`.
|
|
95
91
|
|
|
96
92
|
Equivalent to [`str.endswith()`](https://docs.python.org/3/library/stdtypes.html#str.endswith).
|
|
97
93
|
|
|
98
94
|
Args:
|
|
99
|
-
s: String.
|
|
100
95
|
pattern: string literal
|
|
101
96
|
"""
|
|
102
|
-
return
|
|
97
|
+
return self.endswith(pattern)
|
|
103
98
|
|
|
104
|
-
@func.udf
|
|
105
|
-
def fill(
|
|
99
|
+
@func.udf(is_method=True)
|
|
100
|
+
def fill(self: str, width: int, **kwargs: Any) -> str:
|
|
106
101
|
"""
|
|
107
|
-
Wraps the single paragraph in
|
|
102
|
+
Wraps the single paragraph in string, and returns a single string containing the wrapped paragraph.
|
|
108
103
|
|
|
109
104
|
Equivalent to [`textwrap.fill()`](https://docs.python.org/3/library/textwrap.html#textwrap.fill).
|
|
110
105
|
|
|
111
106
|
Args:
|
|
112
|
-
s: String.
|
|
113
107
|
width: Maximum line width.
|
|
114
108
|
kwargs: Additional keyword arguments to pass to `textwrap.fill()`.
|
|
115
109
|
"""
|
|
116
110
|
import textwrap
|
|
117
|
-
return textwrap.fill(
|
|
111
|
+
return textwrap.fill(self, width, **kwargs)
|
|
118
112
|
|
|
119
|
-
@func.udf
|
|
120
|
-
def find(
|
|
113
|
+
@func.udf(is_method=True)
|
|
114
|
+
def find(self: str, substr: str, start: Optional[int] = 0, end: Optional[int] = None) -> int:
|
|
121
115
|
"""
|
|
122
|
-
Return the lowest index in
|
|
116
|
+
Return the lowest index in string where `substr` is found within the slice `s[start:end]`.
|
|
123
117
|
|
|
124
118
|
Equivalent to [`str.find()`](https://docs.python.org/3/library/stdtypes.html#str.find).
|
|
125
119
|
|
|
126
120
|
Args:
|
|
127
|
-
s: String.
|
|
128
121
|
substr: substring to search for
|
|
129
122
|
start: slice start
|
|
130
123
|
end: slice end
|
|
131
124
|
"""
|
|
132
|
-
return
|
|
125
|
+
return self.find(substr, start, end)
|
|
133
126
|
|
|
134
|
-
@func.udf
|
|
135
|
-
def findall(
|
|
127
|
+
@func.udf(is_method=True)
|
|
128
|
+
def findall(self: str, pattern: str, flags: int = 0) -> list:
|
|
136
129
|
"""
|
|
137
|
-
Find all occurrences of a regular expression pattern in
|
|
130
|
+
Find all occurrences of a regular expression pattern in string.
|
|
138
131
|
|
|
139
132
|
Equivalent to [`re.findall()`](https://docs.python.org/3/library/re.html#re.findall).
|
|
140
133
|
|
|
141
134
|
Args:
|
|
142
|
-
s: String.
|
|
143
135
|
pattern: regular expression pattern
|
|
144
136
|
flags: [flags](https://docs.python.org/3/library/re.html#flags) for the `re` module
|
|
145
137
|
"""
|
|
146
138
|
import re
|
|
147
|
-
return re.findall(pattern,
|
|
139
|
+
return re.findall(pattern, self, flags)
|
|
148
140
|
|
|
149
|
-
@func.udf
|
|
150
|
-
def format(
|
|
141
|
+
@func.udf(is_method=True)
|
|
142
|
+
def format(self: str, *args: Any, **kwargs: Any) -> str:
|
|
151
143
|
"""
|
|
152
144
|
Perform string formatting.
|
|
153
145
|
|
|
154
146
|
Equivalent to [`str.format()`](https://docs.python.org/3/library/stdtypes.html#str.format).
|
|
155
147
|
"""
|
|
156
|
-
return
|
|
148
|
+
return self.format(*args, **kwargs)
|
|
157
149
|
|
|
158
|
-
@func.udf
|
|
159
|
-
def fullmatch(
|
|
150
|
+
@func.udf(is_method=True)
|
|
151
|
+
def fullmatch(self: str, pattern: str, case: bool = True, flags: int = 0) -> bool:
|
|
160
152
|
"""
|
|
161
|
-
Determine if
|
|
153
|
+
Determine if string fully matches a regular expression.
|
|
162
154
|
|
|
163
155
|
Equivalent to [`re.fullmatch()`](https://docs.python.org/3/library/re.html#re.fullmatch).
|
|
164
156
|
|
|
165
157
|
Args:
|
|
166
|
-
s: String.
|
|
167
158
|
pattern: regular expression pattern
|
|
168
159
|
case: if False, ignore case
|
|
169
160
|
flags: [flags](https://docs.python.org/3/library/re.html#flags) for the `re` module
|
|
@@ -171,160 +162,159 @@ def fullmatch(s: str, pattern: str, case: bool = True, flags: int = 0) -> bool:
|
|
|
171
162
|
import re
|
|
172
163
|
if not case:
|
|
173
164
|
flags |= re.IGNORECASE
|
|
174
|
-
_ = bool(re.fullmatch(pattern,
|
|
175
|
-
return bool(re.fullmatch(pattern,
|
|
165
|
+
_ = bool(re.fullmatch(pattern, self, flags))
|
|
166
|
+
return bool(re.fullmatch(pattern, self, flags))
|
|
176
167
|
|
|
177
|
-
@func.udf
|
|
178
|
-
def index(
|
|
168
|
+
@func.udf(is_method=True)
|
|
169
|
+
def index(self: str, substr: str, start: Optional[int] = 0, end: Optional[int] = None) -> int:
|
|
179
170
|
"""
|
|
180
|
-
Return the lowest index in
|
|
171
|
+
Return the lowest index in string where `substr` is found within the slice `[start:end]`.
|
|
172
|
+
Raises ValueError if `substr` is not found.
|
|
181
173
|
|
|
182
174
|
Equivalent to [`str.index()`](https://docs.python.org/3/library/stdtypes.html#str.index).
|
|
183
175
|
|
|
184
176
|
Args:
|
|
185
|
-
s: String.
|
|
186
177
|
substr: substring to search for
|
|
187
178
|
start: slice start
|
|
188
179
|
end: slice end
|
|
189
180
|
"""
|
|
190
|
-
return
|
|
181
|
+
return self.index(substr, start, end)
|
|
191
182
|
|
|
192
|
-
@func.udf
|
|
193
|
-
def isalnum(
|
|
183
|
+
@func.udf(is_method=True)
|
|
184
|
+
def isalnum(self: str) -> bool:
|
|
194
185
|
"""
|
|
195
186
|
Return `True` if all characters in the string are alphanumeric and there is at least one character, `False`
|
|
196
187
|
otherwise.
|
|
197
188
|
|
|
198
189
|
Equivalent to [`str.isalnum()`](https://docs.python.org/3/library/stdtypes.html#str.isalnum
|
|
199
190
|
"""
|
|
200
|
-
return
|
|
191
|
+
return self.isalnum()
|
|
201
192
|
|
|
202
|
-
@func.udf
|
|
203
|
-
def isalpha(
|
|
193
|
+
@func.udf(is_method=True)
|
|
194
|
+
def isalpha(self: str) -> bool:
|
|
204
195
|
"""
|
|
205
196
|
Return `True` if all characters in the string are alphabetic and there is at least one character, `False` otherwise.
|
|
206
197
|
|
|
207
198
|
Equivalent to [`str.isalpha()`](https://docs.python.org/3/library/stdtypes.html#str.isalpha).
|
|
208
199
|
"""
|
|
209
|
-
return
|
|
200
|
+
return self.isalpha()
|
|
210
201
|
|
|
211
|
-
@func.udf
|
|
212
|
-
def isascii(
|
|
202
|
+
@func.udf(is_method=True)
|
|
203
|
+
def isascii(self: str) -> bool:
|
|
213
204
|
"""
|
|
214
205
|
Return `True` if the string is empty or all characters in the string are ASCII, `False` otherwise.
|
|
215
206
|
|
|
216
207
|
Equivalent to [`str.isascii()`](https://docs.python.org/3/library/stdtypes.html#str.isascii).
|
|
217
208
|
"""
|
|
218
|
-
return
|
|
209
|
+
return self.isascii()
|
|
219
210
|
|
|
220
|
-
@func.udf
|
|
221
|
-
def isdecimal(
|
|
211
|
+
@func.udf(is_method=True)
|
|
212
|
+
def isdecimal(self: str) -> bool:
|
|
222
213
|
"""
|
|
223
214
|
Return `True` if all characters in the string are decimal characters and there is at least one character, `False`
|
|
224
215
|
otherwise.
|
|
225
216
|
|
|
226
217
|
Equivalent to [`str.isdecimal()`](https://docs.python.org/3/library/stdtypes.html#str.isdecimal).
|
|
227
218
|
"""
|
|
228
|
-
return
|
|
219
|
+
return self.isdecimal()
|
|
229
220
|
|
|
230
|
-
@func.udf
|
|
231
|
-
def isdigit(
|
|
221
|
+
@func.udf(is_method=True)
|
|
222
|
+
def isdigit(self: str) -> bool:
|
|
232
223
|
"""
|
|
233
224
|
Return `True` if all characters in the string are digits and there is at least one character, `False` otherwise.
|
|
234
225
|
|
|
235
226
|
Equivalent to [`str.isdigit()`](https://docs.python.org/3/library/stdtypes.html#str.isdigit).
|
|
236
227
|
"""
|
|
237
|
-
return
|
|
228
|
+
return self.isdigit()
|
|
238
229
|
|
|
239
|
-
@func.udf
|
|
240
|
-
def isidentifier(
|
|
230
|
+
@func.udf(is_method=True)
|
|
231
|
+
def isidentifier(self: str) -> bool:
|
|
241
232
|
"""
|
|
242
233
|
Return `True` if the string is a valid identifier according to the language definition, `False` otherwise.
|
|
243
234
|
|
|
244
235
|
Equivalent to [`str.isidentifier()`](https://docs.python.org/3/library/stdtypes.html#str.isidentifier)
|
|
245
236
|
"""
|
|
246
|
-
return
|
|
237
|
+
return self.isidentifier()
|
|
247
238
|
|
|
248
239
|
|
|
249
|
-
@func.udf
|
|
250
|
-
def islower(
|
|
240
|
+
@func.udf(is_method=True)
|
|
241
|
+
def islower(self: str) -> bool:
|
|
251
242
|
"""
|
|
252
243
|
Return `True` if all cased characters in the string are lowercase and there is at least one cased character, `False` otherwise.
|
|
253
244
|
|
|
254
245
|
Equivalent to [`str.islower()`](https://docs.python.org/3/library/stdtypes.html#str.islower)
|
|
255
246
|
"""
|
|
256
|
-
return
|
|
247
|
+
return self.islower()
|
|
257
248
|
|
|
258
|
-
@func.udf
|
|
259
|
-
def isnumeric(
|
|
249
|
+
@func.udf(is_method=True)
|
|
250
|
+
def isnumeric(self: str) -> bool:
|
|
260
251
|
"""
|
|
261
252
|
Return `True` if all characters in the string are numeric characters, `False` otherwise.
|
|
262
253
|
|
|
263
254
|
Equivalent to [`str.isnumeric()`](https://docs.python.org/3/library/stdtypes.html#str.isnumeric)
|
|
264
255
|
"""
|
|
265
|
-
return
|
|
256
|
+
return self.isnumeric()
|
|
266
257
|
|
|
267
|
-
@func.udf
|
|
268
|
-
def isupper(
|
|
258
|
+
@func.udf(is_method=True)
|
|
259
|
+
def isupper(self: str) -> bool:
|
|
269
260
|
"""
|
|
270
261
|
Return `True` if all cased characters in the string are uppercase and there is at least one cased character, `False` otherwise.
|
|
271
262
|
|
|
272
263
|
Equivalent to [`str.isupper()`](https://docs.python.org/3/library/stdtypes.html#str.isupper)
|
|
273
264
|
"""
|
|
274
|
-
return
|
|
265
|
+
return self.isupper()
|
|
275
266
|
|
|
276
|
-
@func.udf
|
|
277
|
-
def istitle(
|
|
267
|
+
@func.udf(is_method=True)
|
|
268
|
+
def istitle(self: str) -> bool:
|
|
278
269
|
"""
|
|
279
270
|
Return `True` if the string is a titlecased string and there is at least one character, `False` otherwise.
|
|
280
271
|
|
|
281
272
|
Equivalent to [`str.istitle()`](https://docs.python.org/3/library/stdtypes.html#str.istitle)
|
|
282
273
|
"""
|
|
283
|
-
return
|
|
274
|
+
return self.istitle()
|
|
284
275
|
|
|
285
|
-
@func.udf
|
|
286
|
-
def isspace(
|
|
276
|
+
@func.udf(is_method=True)
|
|
277
|
+
def isspace(self: str) -> bool:
|
|
287
278
|
"""
|
|
288
279
|
Return `True` if there are only whitespace characters in the string and there is at least one character, `False` otherwise.
|
|
289
280
|
|
|
290
281
|
Equivalent to [`str.isspace()`](https://docs.python.org/3/library/stdtypes.html#str.isspace)
|
|
291
282
|
"""
|
|
292
|
-
return
|
|
283
|
+
return self.isspace()
|
|
293
284
|
|
|
294
|
-
@func.udf
|
|
295
|
-
def len(
|
|
285
|
+
@func.udf(is_method=True)
|
|
286
|
+
def len(self: str) -> int:
|
|
296
287
|
"""
|
|
297
288
|
Return the number of characters in the string.
|
|
298
289
|
|
|
299
290
|
Equivalent to [`len(str)`](https://docs.python.org/3/library/functions.html#len)
|
|
300
291
|
"""
|
|
301
|
-
return
|
|
292
|
+
return self.__len__()
|
|
302
293
|
|
|
303
|
-
@func.udf
|
|
304
|
-
def ljust(
|
|
294
|
+
@func.udf(is_method=True)
|
|
295
|
+
def ljust(self: str, width: int, fillchar: str = ' ') -> str:
|
|
305
296
|
"""
|
|
306
|
-
Return the string left-justified in a string of length `width`.
|
|
297
|
+
Return the string left-justified in a string of length `width`.
|
|
307
298
|
|
|
308
299
|
Equivalent to [`str.ljust()`](https://docs.python.org/3/library/stdtypes.html#str.ljust)
|
|
309
300
|
|
|
310
301
|
Args:
|
|
311
|
-
s: String.
|
|
312
302
|
width: Minimum width of resulting string; additional characters will be filled with character defined in `fillchar`.
|
|
313
303
|
fillchar: Additional character for filling.
|
|
314
304
|
"""
|
|
315
|
-
return
|
|
305
|
+
return self.ljust(width, fillchar)
|
|
316
306
|
|
|
317
|
-
@func.udf
|
|
318
|
-
def lower(
|
|
307
|
+
@func.udf(is_method=True)
|
|
308
|
+
def lower(self: str) -> str:
|
|
319
309
|
"""
|
|
320
310
|
Return a copy of the string with all the cased characters converted to lowercase.
|
|
321
311
|
|
|
322
312
|
Equivalent to [`str.lower()`](https://docs.python.org/3/library/stdtypes.html#str.lower)
|
|
323
313
|
"""
|
|
324
|
-
return
|
|
314
|
+
return self.lower()
|
|
325
315
|
|
|
326
|
-
@func.udf
|
|
327
|
-
def lstrip(
|
|
316
|
+
@func.udf(is_method=True)
|
|
317
|
+
def lstrip(self: str, chars: Optional[str] = None) -> str:
|
|
328
318
|
"""
|
|
329
319
|
Return a copy of the string with leading characters removed. The `chars` argument is a string specifying the set of
|
|
330
320
|
characters to be removed. If omitted or `None`, whitespace characters are removed.
|
|
@@ -332,18 +322,16 @@ def lstrip(s: str, chars: Optional[str] = None) -> str:
|
|
|
332
322
|
Equivalent to [`str.lstrip()`](https://docs.python.org/3/library/stdtypes.html#str.lstrip)
|
|
333
323
|
|
|
334
324
|
Args:
|
|
335
|
-
s: String.
|
|
336
325
|
chars: The set of characters to be removed.
|
|
337
326
|
"""
|
|
338
|
-
return
|
|
327
|
+
return self.lstrip(chars)
|
|
339
328
|
|
|
340
|
-
@func.udf
|
|
341
|
-
def match(
|
|
329
|
+
@func.udf(is_method=True)
|
|
330
|
+
def match(self: str, pattern: str, case: bool = True, flags: int = 0) -> bool:
|
|
342
331
|
"""
|
|
343
332
|
Determine if string starts with a match of a regular expression
|
|
344
333
|
|
|
345
334
|
Args:
|
|
346
|
-
s: String.
|
|
347
335
|
pattern: regular expression pattern
|
|
348
336
|
case: if False, ignore case
|
|
349
337
|
flags: [flags](https://docs.python.org/3/library/re.html#flags) for the `re` module
|
|
@@ -351,96 +339,93 @@ def match(s: str, pattern: str, case: bool = True, flags: int = 0) -> bool:
|
|
|
351
339
|
import re
|
|
352
340
|
if not case:
|
|
353
341
|
flags |= re.IGNORECASE
|
|
354
|
-
return bool(re.match(pattern,
|
|
342
|
+
return bool(re.match(pattern, self, flags))
|
|
355
343
|
|
|
356
|
-
@func.udf
|
|
357
|
-
def normalize(
|
|
344
|
+
@func.udf(is_method=True)
|
|
345
|
+
def normalize(self: str, form: str) -> str:
|
|
358
346
|
"""
|
|
359
|
-
Return the Unicode normal form
|
|
347
|
+
Return the Unicode normal form.
|
|
360
348
|
|
|
361
349
|
Equivalent to [`unicodedata.normalize()`](https://docs.python.org/3/library/unicodedata.html#unicodedata.normalize)
|
|
362
350
|
|
|
363
351
|
Args:
|
|
364
|
-
s: String.
|
|
365
352
|
form: Unicode normal form (`‘NFC’`, `‘NFKC’`, `‘NFD’`, `‘NFKD’`)
|
|
366
353
|
"""
|
|
367
354
|
import unicodedata
|
|
368
|
-
return unicodedata.normalize(form,
|
|
355
|
+
return unicodedata.normalize(form, self)
|
|
369
356
|
|
|
370
|
-
@func.udf
|
|
371
|
-
def pad(
|
|
357
|
+
@func.udf(is_method=True)
|
|
358
|
+
def pad(self: str, width: int, side: str = 'left', fillchar: str = ' ') -> str:
|
|
372
359
|
"""
|
|
373
360
|
Pad string up to width
|
|
374
361
|
|
|
375
362
|
Args:
|
|
376
|
-
s: String.
|
|
377
363
|
width: Minimum width of resulting string; additional characters will be filled with character defined in `fillchar`.
|
|
378
364
|
side: Side from which to fill resulting string (`‘left’`, `‘right’`, `‘both’`)
|
|
379
365
|
fillchar: Additional character for filling
|
|
380
366
|
"""
|
|
381
367
|
if side == 'left':
|
|
382
|
-
return
|
|
368
|
+
return self.ljust(width, fillchar)
|
|
383
369
|
elif side == 'right':
|
|
384
|
-
return
|
|
370
|
+
return self.rjust(width, fillchar)
|
|
385
371
|
elif side == 'both':
|
|
386
|
-
return
|
|
372
|
+
return self.center(width, fillchar)
|
|
387
373
|
else:
|
|
388
374
|
raise ValueError(f"Invalid side: {side}")
|
|
389
375
|
|
|
390
|
-
@func.udf
|
|
391
|
-
def partition(
|
|
376
|
+
@func.udf(is_method=True)
|
|
377
|
+
def partition(self: str, sep: str = ' ') -> list:
|
|
392
378
|
"""
|
|
393
|
-
Splits
|
|
379
|
+
Splits string at the first occurrence of `sep`, and returns 3 elements containing the part before the
|
|
394
380
|
separator, the separator itself, and the part after the separator. If the separator is not found, return 3 elements
|
|
395
|
-
containing
|
|
381
|
+
containing string itself, followed by two empty strings.
|
|
396
382
|
"""
|
|
397
|
-
idx =
|
|
383
|
+
idx = self.find(sep)
|
|
398
384
|
if idx == -1:
|
|
399
|
-
return [
|
|
385
|
+
return [self, '', '']
|
|
400
386
|
from builtins import len
|
|
401
|
-
return [
|
|
387
|
+
return [self[:idx], sep, self[idx + len(sep):]]
|
|
402
388
|
|
|
403
|
-
@func.udf
|
|
404
|
-
def removeprefix(
|
|
389
|
+
@func.udf(is_method=True)
|
|
390
|
+
def removeprefix(self: str, prefix: str) -> str:
|
|
405
391
|
"""
|
|
406
|
-
Remove prefix
|
|
392
|
+
Remove prefix. If the prefix is not present, returns string.
|
|
407
393
|
"""
|
|
408
|
-
if
|
|
394
|
+
if self.startswith(prefix):
|
|
409
395
|
# we need to avoid referring to our symbol 'len'
|
|
410
396
|
from builtins import len
|
|
411
|
-
return
|
|
412
|
-
return
|
|
397
|
+
return self[len(prefix):]
|
|
398
|
+
return self
|
|
413
399
|
|
|
414
|
-
@func.udf
|
|
415
|
-
def removesuffix(
|
|
400
|
+
@func.udf(is_method=True)
|
|
401
|
+
def removesuffix(self: str, suffix: str) -> str:
|
|
416
402
|
"""
|
|
417
|
-
Remove suffix
|
|
403
|
+
Remove suffix. If the suffix is not present, returns string.
|
|
418
404
|
"""
|
|
419
|
-
if
|
|
405
|
+
if self.endswith(suffix):
|
|
420
406
|
# we need to avoid referring to our symbol 'len'
|
|
421
407
|
from builtins import len
|
|
422
|
-
return
|
|
423
|
-
return
|
|
408
|
+
return self[:-len(suffix)]
|
|
409
|
+
return self
|
|
424
410
|
|
|
425
|
-
@func.udf
|
|
426
|
-
def repeat(
|
|
411
|
+
@func.udf(is_method=True)
|
|
412
|
+
def repeat(self: str, n: int) -> str:
|
|
427
413
|
"""
|
|
428
|
-
Repeat
|
|
414
|
+
Repeat string `n` times.
|
|
429
415
|
"""
|
|
430
|
-
return
|
|
416
|
+
return self * n
|
|
431
417
|
|
|
432
|
-
@func.udf
|
|
418
|
+
@func.udf(is_method=True)
|
|
433
419
|
def replace(
|
|
434
|
-
|
|
420
|
+
self: str, pattern: str, repl: str, n: int = -1, case: bool = True, flags: int = 0, regex: bool = False
|
|
435
421
|
) -> str:
|
|
436
422
|
"""
|
|
437
|
-
Replace occurrences of `pattern`
|
|
423
|
+
Replace occurrences of `pattern` with `repl`.
|
|
438
424
|
|
|
439
425
|
Equivalent to [`str.replace()`](https://docs.python.org/3/library/stdtypes.html#str.replace) or
|
|
440
426
|
[`re.sub()`](https://docs.python.org/3/library/re.html#re.sub), depending on the value of regex.
|
|
441
427
|
|
|
442
428
|
Args:
|
|
443
|
-
s: String.
|
|
444
429
|
pattern: string literal or regular expression
|
|
445
430
|
repl: replacement string
|
|
446
431
|
n: number of replacements to make (-1 for all)
|
|
@@ -452,181 +437,173 @@ def replace(
|
|
|
452
437
|
import re
|
|
453
438
|
if not case:
|
|
454
439
|
flags |= re.IGNORECASE
|
|
455
|
-
return re.sub(pattern, repl,
|
|
440
|
+
return re.sub(pattern, repl, self, 0 if n == -1 else n, flags)
|
|
456
441
|
else:
|
|
457
|
-
return
|
|
442
|
+
return self.replace(pattern, repl, n)
|
|
458
443
|
|
|
459
|
-
@func.udf
|
|
460
|
-
def rfind(
|
|
444
|
+
@func.udf(is_method=True)
|
|
445
|
+
def rfind(self: str, substr: str, start: Optional[int] = 0, end: Optional[int] = None) -> int:
|
|
461
446
|
"""
|
|
462
|
-
Return the highest index
|
|
447
|
+
Return the highest index where `substr` is found, such that `substr` is contained within `[start:end]`.
|
|
463
448
|
|
|
464
449
|
Equivalent to [`str.rfind()`](https://docs.python.org/3/library/stdtypes.html#str.rfind).
|
|
465
450
|
|
|
466
451
|
Args:
|
|
467
|
-
s: String.
|
|
468
452
|
substr: substring to search for
|
|
469
453
|
start: slice start
|
|
470
454
|
end: slice end
|
|
471
455
|
"""
|
|
472
|
-
return
|
|
456
|
+
return self.rfind(substr, start, end)
|
|
473
457
|
|
|
474
|
-
@func.udf
|
|
475
|
-
def rindex(
|
|
458
|
+
@func.udf(is_method=True)
|
|
459
|
+
def rindex(self: str, substr: str, start: Optional[int] = 0, end: Optional[int] = None) -> int:
|
|
476
460
|
"""
|
|
477
|
-
Return the highest index
|
|
461
|
+
Return the highest index where `substr` is found, such that `substr` is contained within `[start:end]`.
|
|
478
462
|
Raises ValueError if `substr` is not found.
|
|
479
463
|
|
|
480
464
|
Equivalent to [`str.rindex()`](https://docs.python.org/3/library/stdtypes.html#str.rindex).
|
|
481
465
|
"""
|
|
482
|
-
return
|
|
466
|
+
return self.rindex(substr, start, end)
|
|
483
467
|
|
|
484
|
-
@func.udf
|
|
485
|
-
def rjust(
|
|
468
|
+
@func.udf(is_method=True)
|
|
469
|
+
def rjust(self: str, width: int, fillchar: str = ' ') -> str:
|
|
486
470
|
"""
|
|
487
|
-
Return
|
|
471
|
+
Return the string right-justified in a string of length `width`.
|
|
488
472
|
|
|
489
473
|
Equivalent to [`str.rjust()`](https://docs.python.org/3/library/stdtypes.html#str.rjust).
|
|
490
474
|
|
|
491
475
|
Args:
|
|
492
|
-
s: String.
|
|
493
476
|
width: Minimum width of resulting string.
|
|
494
477
|
fillchar: Additional character for filling.
|
|
495
478
|
"""
|
|
496
|
-
return
|
|
479
|
+
return self.rjust(width, fillchar)
|
|
497
480
|
|
|
498
|
-
@func.udf
|
|
499
|
-
def rpartition(
|
|
481
|
+
@func.udf(is_method=True)
|
|
482
|
+
def rpartition(self: str, sep: str = ' ') -> list:
|
|
500
483
|
"""
|
|
501
|
-
This method splits
|
|
484
|
+
This method splits string at the last occurrence of `sep`, and returns a list containing the part before the
|
|
502
485
|
separator, the separator itself, and the part after the separator.
|
|
503
486
|
"""
|
|
504
|
-
idx =
|
|
487
|
+
idx = self.rfind(sep)
|
|
505
488
|
if idx == -1:
|
|
506
|
-
return [
|
|
489
|
+
return [self, '', '']
|
|
507
490
|
from builtins import len
|
|
508
|
-
return [
|
|
491
|
+
return [self[:idx], sep, self[idx + len(sep):]]
|
|
509
492
|
|
|
510
|
-
@func.udf
|
|
511
|
-
def rstrip(
|
|
493
|
+
@func.udf(is_method=True)
|
|
494
|
+
def rstrip(self: str, chars: Optional[str] = None) -> str:
|
|
512
495
|
"""
|
|
513
|
-
Return a copy of
|
|
496
|
+
Return a copy of string with trailing characters removed.
|
|
514
497
|
|
|
515
498
|
Equivalent to [`str.rstrip()`](https://docs.python.org/3/library/stdtypes.html#str.rstrip).
|
|
516
499
|
|
|
517
500
|
Args:
|
|
518
|
-
s: String.
|
|
519
501
|
chars: The set of characters to be removed. If omitted or `None`, whitespace characters are removed.
|
|
520
502
|
"""
|
|
521
|
-
return
|
|
503
|
+
return self.rstrip(chars)
|
|
522
504
|
|
|
523
|
-
@func.udf
|
|
524
|
-
def slice(
|
|
505
|
+
@func.udf(is_method=True)
|
|
506
|
+
def slice(self: str, start: Optional[int] = None, stop: Optional[int] = None, step: Optional[int] = None) -> str:
|
|
525
507
|
"""
|
|
526
|
-
Return a slice
|
|
508
|
+
Return a slice.
|
|
527
509
|
|
|
528
510
|
Args:
|
|
529
|
-
s: String.
|
|
530
511
|
start: slice start
|
|
531
512
|
stop: slice end
|
|
532
513
|
step: slice step
|
|
533
514
|
"""
|
|
534
|
-
return
|
|
515
|
+
return self[start:stop:step]
|
|
535
516
|
|
|
536
|
-
@func.udf
|
|
537
|
-
def slice_replace(
|
|
517
|
+
@func.udf(is_method=True)
|
|
518
|
+
def slice_replace(self: str, start: Optional[int] = None, stop: Optional[int] = None, repl: Optional[str] = None) -> str:
|
|
538
519
|
"""
|
|
539
|
-
Replace a positional slice
|
|
520
|
+
Replace a positional slice with another value.
|
|
540
521
|
|
|
541
522
|
Args:
|
|
542
|
-
s: String.
|
|
543
523
|
start: slice start
|
|
544
524
|
stop: slice end
|
|
545
525
|
repl: replacement value
|
|
546
526
|
"""
|
|
547
|
-
return
|
|
527
|
+
return self[:start] + repl + self[stop:]
|
|
548
528
|
|
|
549
|
-
@func.udf
|
|
550
|
-
def startswith(
|
|
529
|
+
@func.udf(is_method=True)
|
|
530
|
+
def startswith(self: str, pattern: str) -> int:
|
|
551
531
|
"""
|
|
552
|
-
Return `True` if
|
|
532
|
+
Return `True` if string starts with `pattern`, otherwise return `False`.
|
|
553
533
|
|
|
554
534
|
Equivalent to [`str.startswith()`](https://docs.python.org/3/library/stdtypes.html#str.startswith).
|
|
555
535
|
|
|
556
536
|
Args:
|
|
557
|
-
s: String.
|
|
558
537
|
pattern: string literal
|
|
559
538
|
"""
|
|
560
|
-
return
|
|
539
|
+
return self.startswith(pattern)
|
|
561
540
|
|
|
562
|
-
@func.udf
|
|
563
|
-
def strip(
|
|
541
|
+
@func.udf(is_method=True)
|
|
542
|
+
def strip(self: str, chars: Optional[str] = None) -> str:
|
|
564
543
|
"""
|
|
565
|
-
Return a copy of
|
|
544
|
+
Return a copy of string with leading and trailing characters removed.
|
|
566
545
|
|
|
567
546
|
Equivalent to [`str.strip()`](https://docs.python.org/3/library/stdtypes.html#str.strip).
|
|
568
547
|
|
|
569
548
|
Args:
|
|
570
|
-
s: String.
|
|
571
549
|
chars: The set of characters to be removed. If omitted or `None`, whitespace characters are removed.
|
|
572
550
|
"""
|
|
573
|
-
return
|
|
551
|
+
return self.strip(chars)
|
|
574
552
|
|
|
575
|
-
@func.udf
|
|
576
|
-
def swapcase(
|
|
553
|
+
@func.udf(is_method=True)
|
|
554
|
+
def swapcase(self: str) -> str:
|
|
577
555
|
"""
|
|
578
|
-
Return a copy of
|
|
556
|
+
Return a copy of string with uppercase characters converted to lowercase and vice versa.
|
|
579
557
|
|
|
580
558
|
Equivalent to [`str.swapcase()`](https://docs.python.org/3/library/stdtypes.html#str.swapcase).
|
|
581
559
|
"""
|
|
582
|
-
return
|
|
560
|
+
return self.swapcase()
|
|
583
561
|
|
|
584
|
-
@func.udf
|
|
585
|
-
def title(
|
|
562
|
+
@func.udf(is_method=True)
|
|
563
|
+
def title(self: str) -> str:
|
|
586
564
|
"""
|
|
587
|
-
Return a titlecased version of
|
|
588
|
-
lowercase.
|
|
565
|
+
Return a titlecased version of string, i.e. words start with uppercase characters, all remaining cased characters
|
|
566
|
+
are lowercase.
|
|
589
567
|
|
|
590
568
|
Equivalent to [`str.title()`](https://docs.python.org/3/library/stdtypes.html#str.title).
|
|
591
569
|
"""
|
|
592
|
-
return
|
|
570
|
+
return self.title()
|
|
593
571
|
|
|
594
|
-
@func.udf
|
|
595
|
-
def upper(
|
|
572
|
+
@func.udf(is_method=True)
|
|
573
|
+
def upper(self: str) -> str:
|
|
596
574
|
"""
|
|
597
|
-
Return a copy of
|
|
575
|
+
Return a copy of string converted to uppercase.
|
|
576
|
+
|
|
598
577
|
Equivalent to [`str.upper()`](https://docs.python.org/3/library/stdtypes.html#str.upper).
|
|
599
578
|
"""
|
|
600
|
-
return
|
|
579
|
+
return self.upper()
|
|
601
580
|
|
|
602
|
-
@func.udf
|
|
603
|
-
def wrap(
|
|
581
|
+
@func.udf(is_method=True)
|
|
582
|
+
def wrap(self: str, width: int, **kwargs: Any) -> dict:
|
|
604
583
|
"""
|
|
605
|
-
Wraps the single paragraph in
|
|
584
|
+
Wraps the single paragraph in string so every line is at most `width` characters long.
|
|
606
585
|
Returns a list of output lines, without final newlines.
|
|
607
586
|
|
|
608
587
|
Equivalent to [`textwrap.fill()`](https://docs.python.org/3/library/textwrap.html#textwrap.fill).
|
|
609
588
|
|
|
610
589
|
Args:
|
|
611
|
-
s: String.
|
|
612
590
|
width: Maximum line width.
|
|
613
591
|
kwargs: Additional keyword arguments to pass to `textwrap.fill()`.
|
|
614
592
|
"""
|
|
615
593
|
import textwrap
|
|
616
|
-
return textwrap.wrap(
|
|
594
|
+
return textwrap.wrap(self, width, **kwargs)
|
|
617
595
|
|
|
618
|
-
@func.udf
|
|
619
|
-
def zfill(
|
|
596
|
+
@func.udf(is_method=True)
|
|
597
|
+
def zfill(self: str, width: int) -> str:
|
|
620
598
|
"""
|
|
621
|
-
Pad a numeric string
|
|
599
|
+
Pad a numeric string with ASCII `0` on the left to a total length of `width`.
|
|
622
600
|
|
|
623
601
|
Equivalent to [`str.zfill()`](https://docs.python.org/3/library/stdtypes.html#str.zfill).
|
|
624
602
|
|
|
625
603
|
Args:
|
|
626
|
-
s: String.
|
|
627
604
|
width: Minimum width of resulting string.
|
|
628
605
|
"""
|
|
629
|
-
return
|
|
606
|
+
return self.zfill(width)
|
|
630
607
|
|
|
631
608
|
|
|
632
609
|
__all__ = local_public_names(__name__)
|