|
10 | 10 | add, multiply as _multiply_ufunc, |
11 | 11 | ) |
12 | 12 | from numpy._core.multiarray import _vec_string |
| 13 | +from numpy._core.overrides import set_module |
13 | 14 | from numpy._core.umath import ( |
14 | 15 | isalpha, |
15 | 16 | isdigit, |
|
48 | 49 | ) |
49 | 50 |
|
50 | 51 |
|
| 52 | +def _override___module__(): |
| 53 | + for ufunc in [ |
| 54 | + isalnum, isalpha, isdecimal, isdigit, islower, isnumeric, isspace, |
| 55 | + istitle, isupper, str_len, |
| 56 | + ]: |
| 57 | + ufunc.__module__ = "numpy.strings" |
| 58 | + |
| 59 | + |
| 60 | +_override___module__() |
| 61 | + |
| 62 | + |
51 | 63 | __all__ = [ |
52 | 64 | # UFuncs |
53 | 65 | "equal", "not_equal", "less", "less_equal", "greater", "greater_equal", |
@@ -116,6 +128,7 @@ def _clean_args(*args): |
116 | 128 | return newargs |
117 | 129 |
|
118 | 130 |
|
| 131 | +@set_module("numpy.strings") |
119 | 132 | def multiply(a, i): |
120 | 133 | """ |
121 | 134 | Return (a * i), that is string multiple concatenation, |
@@ -179,6 +192,7 @@ def multiply(a, i): |
179 | 192 | return _multiply_ufunc(a, i, out=out) |
180 | 193 |
|
181 | 194 |
|
| 195 | +@set_module("numpy.strings") |
182 | 196 | def mod(a, values): |
183 | 197 | """ |
184 | 198 | Return (a % i), that is pre-Python 2.6 string formatting |
@@ -215,6 +229,7 @@ def mod(a, values): |
215 | 229 | _vec_string(a, np.object_, '__mod__', (values,)), a) |
216 | 230 |
|
217 | 231 |
|
| 232 | +@set_module("numpy.strings") |
218 | 233 | def find(a, sub, start=0, end=None): |
219 | 234 | """ |
220 | 235 | For each element, return the lowest index in the string where |
@@ -252,6 +267,7 @@ def find(a, sub, start=0, end=None): |
252 | 267 | return _find_ufunc(a, sub, start, end) |
253 | 268 |
|
254 | 269 |
|
| 270 | +@set_module("numpy.strings") |
255 | 271 | def rfind(a, sub, start=0, end=None): |
256 | 272 | """ |
257 | 273 | For each element, return the highest index in the string where |
@@ -294,6 +310,7 @@ def rfind(a, sub, start=0, end=None): |
294 | 310 | return _rfind_ufunc(a, sub, start, end) |
295 | 311 |
|
296 | 312 |
|
| 313 | +@set_module("numpy.strings") |
297 | 314 | def index(a, sub, start=0, end=None): |
298 | 315 | """ |
299 | 316 | Like `find`, but raises :exc:`ValueError` when the substring is not found. |
@@ -327,6 +344,7 @@ def index(a, sub, start=0, end=None): |
327 | 344 | return _index_ufunc(a, sub, start, end) |
328 | 345 |
|
329 | 346 |
|
| 347 | +@set_module("numpy.strings") |
330 | 348 | def rindex(a, sub, start=0, end=None): |
331 | 349 | """ |
332 | 350 | Like `rfind`, but raises :exc:`ValueError` when the substring `sub` is |
@@ -360,6 +378,7 @@ def rindex(a, sub, start=0, end=None): |
360 | 378 | return _rindex_ufunc(a, sub, start, end) |
361 | 379 |
|
362 | 380 |
|
| 381 | +@set_module("numpy.strings") |
363 | 382 | def count(a, sub, start=0, end=None): |
364 | 383 | """ |
365 | 384 | Returns an array with the number of non-overlapping occurrences of |
@@ -404,6 +423,7 @@ def count(a, sub, start=0, end=None): |
404 | 423 | return _count_ufunc(a, sub, start, end) |
405 | 424 |
|
406 | 425 |
|
| 426 | +@set_module("numpy.strings") |
407 | 427 | def startswith(a, prefix, start=0, end=None): |
408 | 428 | """ |
409 | 429 | Returns a boolean array which is `True` where the string element |
@@ -444,6 +464,7 @@ def startswith(a, prefix, start=0, end=None): |
444 | 464 | return _startswith_ufunc(a, prefix, start, end) |
445 | 465 |
|
446 | 466 |
|
| 467 | +@set_module("numpy.strings") |
447 | 468 | def endswith(a, suffix, start=0, end=None): |
448 | 469 | """ |
449 | 470 | Returns a boolean array which is `True` where the string element |
@@ -484,6 +505,7 @@ def endswith(a, suffix, start=0, end=None): |
484 | 505 | return _endswith_ufunc(a, suffix, start, end) |
485 | 506 |
|
486 | 507 |
|
| 508 | +@set_module("numpy.strings") |
487 | 509 | def decode(a, encoding=None, errors=None): |
488 | 510 | r""" |
489 | 511 | Calls :meth:`bytes.decode` element-wise. |
@@ -531,6 +553,7 @@ def decode(a, encoding=None, errors=None): |
531 | 553 | np.str_('')) |
532 | 554 |
|
533 | 555 |
|
| 556 | +@set_module("numpy.strings") |
534 | 557 | def encode(a, encoding=None, errors=None): |
535 | 558 | """ |
536 | 559 | Calls :meth:`str.encode` element-wise. |
@@ -575,6 +598,7 @@ def encode(a, encoding=None, errors=None): |
575 | 598 | np.bytes_(b'')) |
576 | 599 |
|
577 | 600 |
|
| 601 | +@set_module("numpy.strings") |
578 | 602 | def expandtabs(a, tabsize=8): |
579 | 603 | """ |
580 | 604 | Return a copy of each string element where all tab characters are |
@@ -626,6 +650,7 @@ def expandtabs(a, tabsize=8): |
626 | 650 | return _expandtabs(a, tabsize, out=out) |
627 | 651 |
|
628 | 652 |
|
| 653 | +@set_module("numpy.strings") |
629 | 654 | def center(a, width, fillchar=' '): |
630 | 655 | """ |
631 | 656 | Return a copy of `a` with its elements centered in a string of |
@@ -693,6 +718,7 @@ def center(a, width, fillchar=' '): |
693 | 718 | return _center(a, width, fillchar, out=out) |
694 | 719 |
|
695 | 720 |
|
| 721 | +@set_module("numpy.strings") |
696 | 722 | def ljust(a, width, fillchar=' '): |
697 | 723 | """ |
698 | 724 | Return an array with the elements of `a` left-justified in a |
@@ -756,6 +782,7 @@ def ljust(a, width, fillchar=' '): |
756 | 782 | return _ljust(a, width, fillchar, out=out) |
757 | 783 |
|
758 | 784 |
|
| 785 | +@set_module("numpy.strings") |
759 | 786 | def rjust(a, width, fillchar=' '): |
760 | 787 | """ |
761 | 788 | Return an array with the elements of `a` right-justified in a |
@@ -819,6 +846,7 @@ def rjust(a, width, fillchar=' '): |
819 | 846 | return _rjust(a, width, fillchar, out=out) |
820 | 847 |
|
821 | 848 |
|
| 849 | +@set_module("numpy.strings") |
822 | 850 | def zfill(a, width): |
823 | 851 | """ |
824 | 852 | Return the numeric string left-filled with zeros. A leading |
@@ -865,6 +893,7 @@ def zfill(a, width): |
865 | 893 | return _zfill(a, width, out=out) |
866 | 894 |
|
867 | 895 |
|
| 896 | +@set_module("numpy.strings") |
868 | 897 | def lstrip(a, chars=None): |
869 | 898 | """ |
870 | 899 | For each element in `a`, return a copy with the leading characters |
@@ -912,6 +941,7 @@ def lstrip(a, chars=None): |
912 | 941 | return _lstrip_chars(a, chars) |
913 | 942 |
|
914 | 943 |
|
| 944 | +@set_module("numpy.strings") |
915 | 945 | def rstrip(a, chars=None): |
916 | 946 | """ |
917 | 947 | For each element in `a`, return a copy with the trailing characters |
@@ -954,6 +984,7 @@ def rstrip(a, chars=None): |
954 | 984 | return _rstrip_chars(a, chars) |
955 | 985 |
|
956 | 986 |
|
| 987 | +@set_module("numpy.strings") |
957 | 988 | def strip(a, chars=None): |
958 | 989 | """ |
959 | 990 | For each element in `a`, return a copy with the leading and |
@@ -1000,6 +1031,7 @@ def strip(a, chars=None): |
1000 | 1031 | return _strip_chars(a, chars) |
1001 | 1032 |
|
1002 | 1033 |
|
| 1034 | +@set_module("numpy.strings") |
1003 | 1035 | def upper(a): |
1004 | 1036 | """ |
1005 | 1037 | Return an array with the elements converted to uppercase. |
@@ -1036,6 +1068,7 @@ def upper(a): |
1036 | 1068 | return _vec_string(a_arr, a_arr.dtype, 'upper') |
1037 | 1069 |
|
1038 | 1070 |
|
| 1071 | +@set_module("numpy.strings") |
1039 | 1072 | def lower(a): |
1040 | 1073 | """ |
1041 | 1074 | Return an array with the elements converted to lowercase. |
@@ -1072,6 +1105,7 @@ def lower(a): |
1072 | 1105 | return _vec_string(a_arr, a_arr.dtype, 'lower') |
1073 | 1106 |
|
1074 | 1107 |
|
| 1108 | +@set_module("numpy.strings") |
1075 | 1109 | def swapcase(a): |
1076 | 1110 | """ |
1077 | 1111 | Return element-wise a copy of the string with |
@@ -1111,6 +1145,7 @@ def swapcase(a): |
1111 | 1145 | return _vec_string(a_arr, a_arr.dtype, 'swapcase') |
1112 | 1146 |
|
1113 | 1147 |
|
| 1148 | +@set_module("numpy.strings") |
1114 | 1149 | def capitalize(a): |
1115 | 1150 | """ |
1116 | 1151 | Return a copy of ``a`` with only the first character of each element |
@@ -1150,6 +1185,7 @@ def capitalize(a): |
1150 | 1185 | return _vec_string(a_arr, a_arr.dtype, 'capitalize') |
1151 | 1186 |
|
1152 | 1187 |
|
| 1188 | +@set_module("numpy.strings") |
1153 | 1189 | def title(a): |
1154 | 1190 | """ |
1155 | 1191 | Return element-wise title cased version of string or unicode. |
@@ -1191,6 +1227,7 @@ def title(a): |
1191 | 1227 | return _vec_string(a_arr, a_arr.dtype, 'title') |
1192 | 1228 |
|
1193 | 1229 |
|
| 1230 | +@set_module("numpy.strings") |
1194 | 1231 | def replace(a, old, new, count=-1): |
1195 | 1232 | """ |
1196 | 1233 | For each element in ``a``, return a copy of the string with |
@@ -1416,6 +1453,7 @@ def _splitlines(a, keepends=None): |
1416 | 1453 | a, np.object_, 'splitlines', _clean_args(keepends)) |
1417 | 1454 |
|
1418 | 1455 |
|
| 1456 | +@set_module("numpy.strings") |
1419 | 1457 | def partition(a, sep): |
1420 | 1458 | """ |
1421 | 1459 | Partition each element in ``a`` around ``sep``. |
@@ -1483,6 +1521,7 @@ def partition(a, sep): |
1483 | 1521 | return _partition_index(a, sep, pos, out=(out["f0"], out["f1"], out["f2"])) |
1484 | 1522 |
|
1485 | 1523 |
|
| 1524 | +@set_module("numpy.strings") |
1486 | 1525 | def rpartition(a, sep): |
1487 | 1526 | """ |
1488 | 1527 | Partition (split) each element around the right-most separator. |
@@ -1551,6 +1590,7 @@ def rpartition(a, sep): |
1551 | 1590 | a, sep, pos, out=(out["f0"], out["f1"], out["f2"])) |
1552 | 1591 |
|
1553 | 1592 |
|
| 1593 | +@set_module("numpy.strings") |
1554 | 1594 | def translate(a, table, deletechars=None): |
1555 | 1595 | """ |
1556 | 1596 | For each element in `a`, return a copy of the string where all |
|
0 commit comments