Skip to content

Commit 27065a2

Browse files
author
Joost Kranendonk
authored
Reraise TypeError only with wrong number of args
This influences all StringMethods were a used passes a callable to a StringMethod, e.g. `.str.replace`, that expects a wrong number of arguments. See pandas-dev#15056
1 parent ae04a3e commit 27065a2

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

pandas/core/strings.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,14 @@ def _map(f, arr, na_mask=False, na_value=np.nan, dtype=object):
167167
try:
168168
convert = not all(mask)
169169
result = lib.map_infer_mask(arr, f, mask.view(np.uint8), convert)
170-
except (TypeError, AttributeError):
170+
except (TypeError, AttributeError) as e:
171+
re_missing = (r'missing \d+ required (positional|keyword-only) '
172+
'arguments?')
173+
re_takes = (r'takes (from)?\d+ (to \d+)?positional arguments? '
174+
'but \d+ (was|were) given')
175+
if len(e.args) >= 1 and (re.search(re_missing, e.args[0])
176+
or re.search(re_takes, e.args[0])):
177+
raise e
171178

172179
def g(x):
173180
try:

0 commit comments

Comments
 (0)