|
9 | 9 | import textwrap
|
10 | 10 |
|
11 | 11 |
|
| 12 | +_shared_docs = dict() |
| 13 | + |
| 14 | + |
12 | 15 | def _get_array_list(arr, others):
|
13 | 16 | from pandas.core.series import Series
|
14 | 17 |
|
@@ -124,17 +127,6 @@ def g(x):
|
124 | 127 | return lib.map_infer(arr, f)
|
125 | 128 |
|
126 | 129 |
|
127 |
| -def str_title(arr): |
128 |
| - """ |
129 |
| - Convert strings to titlecased version |
130 |
| -
|
131 |
| - Returns |
132 |
| - ------- |
133 |
| - titled : array |
134 |
| - """ |
135 |
| - return _na_map(lambda x: x.title(), arr) |
136 |
| - |
137 |
| - |
138 | 130 | def str_count(arr, pat, flags=0):
|
139 | 131 | """
|
140 | 132 | Count occurrences of pattern in each string
|
@@ -197,7 +189,8 @@ def str_contains(arr, pat, case=True, flags=0, na=np.nan, regex=True):
|
197 | 189 | else:
|
198 | 190 | upper_pat = pat.upper()
|
199 | 191 | f = lambda x: upper_pat in x
|
200 |
| - return _na_map(f, str_upper(arr), na, dtype=bool) |
| 192 | + uppered = _na_map(lambda x: x.upper(), arr) |
| 193 | + return _na_map(f, uppered, na, dtype=bool) |
201 | 194 | return _na_map(f, arr, na, dtype=bool)
|
202 | 195 |
|
203 | 196 |
|
@@ -239,28 +232,6 @@ def str_endswith(arr, pat, na=np.nan):
|
239 | 232 | return _na_map(f, arr, na, dtype=bool)
|
240 | 233 |
|
241 | 234 |
|
242 |
| -def str_lower(arr): |
243 |
| - """ |
244 |
| - Convert strings in array to lowercase |
245 |
| -
|
246 |
| - Returns |
247 |
| - ------- |
248 |
| - lowercase : array |
249 |
| - """ |
250 |
| - return _na_map(lambda x: x.lower(), arr) |
251 |
| - |
252 |
| - |
253 |
| -def str_upper(arr): |
254 |
| - """ |
255 |
| - Convert strings in array to uppercase |
256 |
| -
|
257 |
| - Returns |
258 |
| - ------- |
259 |
| - uppercase : array |
260 |
| - """ |
261 |
| - return _na_map(lambda x: x.upper(), arr) |
262 |
| - |
263 |
| - |
264 | 235 | def str_replace(arr, pat, repl, n=-1, case=True, flags=0):
|
265 | 236 | """
|
266 | 237 | Replace
|
@@ -553,17 +524,6 @@ def str_join(arr, sep):
|
553 | 524 | return _na_map(sep.join, arr)
|
554 | 525 |
|
555 | 526 |
|
556 |
| -def str_len(arr): |
557 |
| - """ |
558 |
| - Compute length of each string in array. |
559 |
| -
|
560 |
| - Returns |
561 |
| - ------- |
562 |
| - lengths : array |
563 |
| - """ |
564 |
| - return _na_map(len, arr, dtype=int) |
565 |
| - |
566 |
| - |
567 | 527 | def str_findall(arr, pat, flags=0):
|
568 | 528 | """
|
569 | 529 | Find all occurrences of pattern or regular expression
|
@@ -884,14 +844,16 @@ def str_encode(arr, encoding, errors="strict"):
|
884 | 844 | return _na_map(f, arr)
|
885 | 845 |
|
886 | 846 |
|
887 |
| -def _noarg_wrapper(f): |
| 847 | +def _noarg_wrapper(f, docstring=None, **kargs): |
888 | 848 | def wrapper(self):
|
889 |
| - result = f(self.series) |
| 849 | + result = _na_map(f, self.series, **kargs) |
890 | 850 | return self._wrap_result(result)
|
891 | 851 |
|
892 | 852 | wrapper.__name__ = f.__name__
|
893 |
| - if f.__doc__: |
894 |
| - wrapper.__doc__ = f.__doc__ |
| 853 | + if docstring is not None: |
| 854 | + wrapper.__doc__ = docstring |
| 855 | + else: |
| 856 | + raise ValueError('Provide docstring') |
895 | 857 |
|
896 | 858 | return wrapper
|
897 | 859 |
|
@@ -1076,7 +1038,47 @@ def get_dummies(self, sep='|'):
|
1076 | 1038 | findall = _pat_wrapper(str_findall, flags=True)
|
1077 | 1039 | extract = _pat_wrapper(str_extract, flags=True)
|
1078 | 1040 |
|
1079 |
| - len = _noarg_wrapper(str_len) |
1080 |
| - lower = _noarg_wrapper(str_lower) |
1081 |
| - upper = _noarg_wrapper(str_upper) |
1082 |
| - title = _noarg_wrapper(str_title) |
| 1041 | + _shared_docs['len'] = (""" |
| 1042 | + Compute length of each string in array. |
| 1043 | +
|
| 1044 | + Returns |
| 1045 | + ------- |
| 1046 | + lengths : array |
| 1047 | + """) |
| 1048 | + len = _noarg_wrapper(len, docstring=_shared_docs['len'], dtype=int) |
| 1049 | + |
| 1050 | + _shared_docs['casemethods'] = (""" |
| 1051 | + Convert strings in array to %s |
| 1052 | +
|
| 1053 | + Returns |
| 1054 | + ------- |
| 1055 | + uppercase : array |
| 1056 | + """) |
| 1057 | + lower = _noarg_wrapper(lambda x: x.lower(), |
| 1058 | + docstring=_shared_docs['casemethods'] % 'lowercase') |
| 1059 | + upper = _noarg_wrapper(lambda x: x.upper(), |
| 1060 | + docstring=_shared_docs['casemethods'] % 'uppercase') |
| 1061 | + title = _noarg_wrapper(lambda x: x.title(), |
| 1062 | + docstring=_shared_docs['casemethods'] % 'titlecase') |
| 1063 | + |
| 1064 | + _shared_docs['ismethods'] = (""" |
| 1065 | + Check whether all characters in each string in the array are %s |
| 1066 | +
|
| 1067 | + Returns |
| 1068 | + ------- |
| 1069 | + Series of boolean values |
| 1070 | + """) |
| 1071 | + isalnum = _noarg_wrapper(lambda x: x.isalnum(), |
| 1072 | + docstring=_shared_docs['ismethods'] % 'alphanumeric') |
| 1073 | + isalpha = _noarg_wrapper(lambda x: x.isalpha(), |
| 1074 | + docstring=_shared_docs['ismethods'] % 'alphabetic') |
| 1075 | + isdigit = _noarg_wrapper(lambda x: x.isdigit(), |
| 1076 | + docstring=_shared_docs['ismethods'] % 'digits') |
| 1077 | + isspace = _noarg_wrapper(lambda x: x.isspace(), |
| 1078 | + docstring=_shared_docs['ismethods'] % 'whitespace') |
| 1079 | + islower = _noarg_wrapper(lambda x: x.islower(), |
| 1080 | + docstring=_shared_docs['ismethods'] % 'lowercase') |
| 1081 | + isupper = _noarg_wrapper(lambda x: x.isupper(), |
| 1082 | + docstring=_shared_docs['ismethods'] % 'uppercase') |
| 1083 | + istitle = _noarg_wrapper(lambda x: x.istitle(), |
| 1084 | + docstring=_shared_docs['ismethods'] % 'titlecase') |
0 commit comments