pixeltable 0.2.12__py3-none-any.whl → 0.2.14__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.

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